-
-
Notifications
You must be signed in to change notification settings - Fork 627
Expand file tree
/
Copy pathtest.mjs
More file actions
65 lines (56 loc) · 1.6 KB
/
test.mjs
File metadata and controls
65 lines (56 loc) · 1.6 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { createRequire } from 'module';
import { fileURLToPath } from 'url';
import { test, expect } from 'vitest';
import { rollup } from 'rollup';
import dataUri from 'current-package';
import { testBundle } from '../../../util/test.js';
const DIRNAME = fileURLToPath(new URL('./fixtures', import.meta.url));
process.chdir(DIRNAME);
test('json', async () => {
const bundle = await rollup({
input: 'json.js',
plugins: [dataUri()]
});
const { code } = await testBundle(undefined, bundle);
expect(code).toMatchSnapshot();
});
test('import', async () => {
const bundle = await rollup({
input: 'import.js',
plugins: [dataUri()]
});
const { code } = await testBundle(undefined, bundle);
expect(code).toMatchSnapshot();
});
test('bad json', async () => {
const fn = () =>
rollup({
input: 'bad-json.js',
plugins: [dataUri()]
});
const error = await fn().then(
() => null,
(caught) => caught
);
expect(error).not.toBeNull();
const { code, plugin, pluginCode } = error;
expect({ code, plugin, pluginCode }).toMatchSnapshot();
});
test('base64', async () => {
const bundle = await rollup({
input: 'base64.js',
plugins: [dataUri()]
});
const { code } = await testBundle(undefined, bundle);
expect(code).toMatchSnapshot();
});
test('works as CJS plugin', async () => {
const require = createRequire(import.meta.url);
const dataUriCjs = require('current-package');
const bundle = await rollup({
input: 'json.js',
plugins: [dataUriCjs()]
});
const { code } = await testBundle(undefined, bundle);
expect(code).toMatchSnapshot();
});