|
| 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