Skip to content

Commit 5de283c

Browse files
committed
test: add some tests to kick things off
1 parent 6b9f0e9 commit 5de283c

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/fixtures/test.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"example": "1.0.0"
4+
}
5+
}

src/index.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import test from 'ava'
2+
import { testProp, fc } from 'ava-fast-check'
3+
import { Arbitrary } from 'fast-check'
4+
import { PluginContext, Plugin } from 'rollup'
5+
import externals, { ExternalsOptions } from './index'
6+
7+
// Returns an arbitrary for generating externals options objects
8+
const externalsOptionsArbitrary = (): Arbitrary<ExternalsOptions> =>
9+
fc.record({
10+
packagePath: fc.string(),
11+
builtins: fc.boolean(),
12+
deps: fc.boolean(),
13+
devDeps: fc.boolean(),
14+
peerDeps: fc.boolean(),
15+
optDeps: fc.boolean(),
16+
include: fc.oneof(fc.string(), fc.array(fc.string())),
17+
exclude: fc.oneof(fc.string(), fc.array(fc.string())),
18+
except: fc.oneof(fc.string(), fc.array(fc.string()))
19+
}, { withDeletedKeys: true })
20+
21+
testProp(
22+
'does not throw on constructing plugin object for valid input',
23+
[externalsOptionsArbitrary()],
24+
options => {
25+
try {
26+
externals(options)
27+
return true
28+
} catch {
29+
return false
30+
}
31+
}
32+
)
33+
34+
test('does not mark "dependencies" dependency as external by default', t => {
35+
const source = 'example'
36+
const importer = 'me'
37+
const plugin = externals({ packagePath: './fixtures/test.json' }) as Plugin & PluginContext
38+
39+
t.is(plugin.resolveId(source, importer), null)
40+
})

0 commit comments

Comments
 (0)