Skip to content

Commit 66b495c

Browse files
committed
Update tests
1 parent 3cb4ed8 commit 66b495c

File tree

1 file changed

+59
-11
lines changed

1 file changed

+59
-11
lines changed

src/index.test.ts

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ import { PluginContext, Plugin, NormalizedInputOptions } from 'rollup'
55
import externals, { ExternalsOptions } from './index'
66
import { join } from "path"
77

8+
type TestedPlugin = Required<Plugin> & PluginContext
9+
const fakeInputOptions = {} as NormalizedInputOptions
10+
811
// Returns an arbitrary for generating externals options objects
912
const externalsOptionsArbitrary = (): Arbitrary<ExternalsOptions> => fc.record({
1013
packagePath: fc.string(),
1114
builtins: fc.boolean(),
12-
prefixedBuiltins: fc.oneof(fc.boolean(), fc.constant<'strip'>('strip')),
15+
prefixedBuiltins: fc.oneof(fc.boolean(), fc.constant<'strip'>('strip'), fc.constant<'add'>('add')),
1316
deps: fc.boolean(),
1417
devDeps: fc.boolean(),
1518
peerDeps: fc.boolean(),
1619
optDeps: fc.boolean(),
1720
include: fc.oneof(fc.string(), fc.array(fc.string())),
18-
exclude: fc.oneof(fc.string(), fc.array(fc.string())),
19-
except: fc.oneof(fc.string(), fc.array(fc.string()))
21+
exclude: fc.oneof(fc.string(), fc.array(fc.string()))
2022
}, { withDeletedKeys: true })
2123

2224
testProp(
@@ -36,11 +38,10 @@ test('marks "dependencies" as external by default', async t => {
3638
process.chdir(__dirname)
3739

3840
const source = 'example'
39-
const importer = 'me'
40-
const plugin = externals({ packagePath: './fixtures/test.json' }) as Required<Plugin> & PluginContext
41+
const plugin = externals({ packagePath: './fixtures/test.json' }) as TestedPlugin
4142

42-
await plugin.buildStart({} as NormalizedInputOptions)
43-
t.deepEqual(await plugin.resolveId(source, importer, { isEntry: false }), { id: source, external: true })
43+
await plugin.buildStart(fakeInputOptions)
44+
t.false(await plugin.resolveId(source))
4445
})
4546

4647
const path = (...paths: string[]): string => join(__dirname, ...paths)
@@ -49,11 +50,58 @@ test.serial('monorepo usage', async t => {
4950
const cwd = path('fixtures/monorepo/packages/package')
5051
process.chdir(cwd)
5152

52-
const importer = 'me'
53-
const plugin = externals() as Required<Plugin> & PluginContext
54-
await plugin.buildStart({} as NormalizedInputOptions)
53+
const plugin = externals() as TestedPlugin
54+
await plugin.buildStart(fakeInputOptions)
5555

5656
for (const source of ['@babel/core', 'typescript', 'rollup', 'lodash', 'express', 'chalk']) {
57-
t.deepEqual(await plugin.resolveId(source, importer, { isEntry: false }), { id: source, external: true })
57+
t.false(await plugin.resolveId(source))
58+
}
59+
})
60+
61+
test('prefixedBuiltins === false', async t => {
62+
const plugin = externals({ prefixedBuiltins: false }) as TestedPlugin
63+
await plugin.buildStart(fakeInputOptions)
64+
65+
for (const source of [ 'node:path', 'path' ]) {
66+
t.deepEqual(
67+
await plugin.resolveId(source),
68+
{ id: source, external: true }
69+
)
70+
}
71+
})
72+
73+
test('prefixedBuiltins === true (default)', async t => {
74+
const plugin = externals({ prefixedBuiltins: true }) as TestedPlugin
75+
await plugin.buildStart(fakeInputOptions)
76+
77+
for (const source of [ 'node:path', 'path' ]) {
78+
t.deepEqual(
79+
await plugin.resolveId(source),
80+
{ id: source, external: true }
81+
)
82+
}
83+
})
84+
85+
test('prefixedBuiltins === "strip"', async t => {
86+
const plugin = externals({ prefixedBuiltins: 'strip' }) as TestedPlugin
87+
await plugin.buildStart(fakeInputOptions)
88+
89+
for (const source of [ 'node:path', 'path' ]) {
90+
t.deepEqual(
91+
await plugin.resolveId(source),
92+
{ id: 'path', external: true }
93+
)
94+
}
95+
})
96+
97+
test('prefixedBuiltins === "add"', async t => {
98+
const plugin = externals({ prefixedBuiltins: 'add' }) as TestedPlugin
99+
await plugin.buildStart(fakeInputOptions)
100+
101+
for (const source of [ 'node:path', 'path' ]) {
102+
t.deepEqual(
103+
await plugin.resolveId(source),
104+
{ id: 'node:path', external: true }
105+
)
58106
}
59107
})

0 commit comments

Comments
 (0)