13
13
// limitations under the License.
14
14
15
15
import assert from 'node:assert'
16
- import { test , describe , before , beforeEach } from 'node:test'
17
- import { $ } from '../build/index.js'
16
+ import { test , describe } from 'node:test'
17
+ import { $ , tmpfile , fs } from '../build/index.js'
18
18
import { installDeps , parseDeps } from '../build/deps.js'
19
19
20
20
describe ( 'deps' , ( ) => {
@@ -27,12 +27,39 @@ describe('deps', () => {
27
27
assert ( ( await import ( 'lodash-es' ) ) . pick instanceof Function )
28
28
} )
29
29
30
+ test ( 'installDeps() loader works via JS API with custom npm registry URL' , async ( ) => {
31
+ await installDeps (
32
+ {
33
+ '@jsr/std__internal' : '1.0.5' ,
34
+ } ,
35
+ undefined ,
36
+ 'https://npm.jsr.io'
37
+ )
38
+
39
+ assert ( ( await import ( '@jsr/std__internal' ) ) . diff instanceof Function )
40
+ } )
41
+
30
42
test ( 'installDeps() loader works via CLI' , async ( ) => {
31
43
const out =
32
44
await $ `node build/cli.js --install <<< 'import _ from "lodash" /* @4.17.15 */; console.log(_.VERSION)'`
33
45
assert . match ( out . stdout , / 4 .1 7 .1 5 / )
34
46
} )
35
47
48
+ test ( 'installDeps() loader works via CLI with custom npm registry URL' , async ( ) => {
49
+ const code =
50
+ 'import { diff } from "@jsr/std__internal";console.log(diff instanceof Function)'
51
+ const file = tmpfile ( 'index.mjs' , code )
52
+
53
+ let out =
54
+ await $ `node build/cli.js --i --registry=https://npm.jsr.io ${ file } `
55
+ fs . remove ( file )
56
+ assert . match ( out . stdout , / t r u e / )
57
+
58
+ out =
59
+ await $ `node build/cli.js -i --registry=https://npm.jsr.io <<< ${ code } `
60
+ assert . match ( out . stdout , / t r u e / )
61
+ } )
62
+
36
63
test ( 'parseDeps(): import or require' , async ( ) => {
37
64
; [
38
65
[ `import "foo"` , { foo : 'latest' } ] ,
@@ -82,11 +109,11 @@ describe('deps', () => {
82
109
require('a') // @1.0.0
83
110
const b =require('b') /* @2.0.0 */
84
111
const c = {
85
- c:require('c') /* @3.0.0 */,
86
- d: await import('d') /* @4.0.0 */,
112
+ c:require('c') /* @3.0.0 */,
113
+ d: await import('d') /* @4.0.0 */,
87
114
...require('e') /* @5.0.0 */
88
115
}
89
- const f = [...require('f') /* @6.0.0 */]
116
+ const f = [...require('f') /* @6.0.0 */]
90
117
;require('g'); // @7.0.0
91
118
const h = 1 *require('h') // @8.0.0
92
119
{require('i') /* @9.0.0 */}
@@ -96,7 +123,7 @@ describe('deps', () => {
96
123
import path from 'path'
97
124
import foo from "foo"
98
125
// import aaa from 'a'
99
- /* import bbb from 'b' */
126
+ /* import bbb from 'b' */
100
127
import bar from "bar" /* @1.0.0 */
101
128
import baz from "baz" // @^2.0
102
129
import qux from "@qux/pkg/entry" // @^3.0
0 commit comments