-
Notifications
You must be signed in to change notification settings - Fork 65
/
index.spec.js
50 lines (43 loc) · 1.64 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import 'ses'
import test from 'ava'
import { run } from '../src/index.js'
import { loadJSONFixture } from './fixture-util.js'
test('basic operation - run an app without dependencies', async (t) => {
const entryFile = new URL('./fixture/no-deps/app.js', import.meta.url)
const policy = {
resources: {},
}
const result = await run(entryFile, policy)
// this is needed because `result` has a `Symbol.toStringTag` prop which confuses AVA
t.deepEqual({ .../** @type {object} */ (result) }, { hello: 'world' })
})
test.failing('dynamic imports - run a pure-JS app', async (t) => {
const { readPowers } = await loadJSONFixture(
new URL('./fixture/json/dynamic.json', import.meta.url)
)
const entryFile = '/index.js'
// dummy needs to require other things that are not dependencies of anything else
const result = await run(entryFile, {
readPowers,
policyOverride: {
resources: {
'dynamic-require': {
// if we do this we need to recognize it in endo
packages: {
dummy: 'dynamic',
},
},
},
},
})
t.deepEqual({ .../** @type {object} */ (result) }, { hello: 'hello world' })
})
test.failing('dynamic imports - run a native module', async (t) => {
const { readPowers } = await loadJSONFixture(
new URL('./fixture/json/native.json', import.meta.url)
)
const entryFile = '/index.js'
// TODO: the runtime prints no warnings for `node-gyp-build`, which _conditionally_ contains a dynamic require. It should throw a TypeError
const result = await run(entryFile, { readPowers })
t.deepEqual({ .../** @type {object} */ (result) }, { hello: 'hello world' })
})