forked from umijs/father
/
expect.ts
36 lines (30 loc) · 1.18 KB
/
expect.ts
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
import { readFileSync } from 'fs';
import { join } from 'path';
export default (files: Record<string, string>) => {
// umd
expect(files['umd/index.min.js']).toContain(
'//# sourceMappingURL=index.min.js.map',
);
// esm transform by swc
expect('esm/index.js.map' in files).toBe(true);
expect(files['esm/index.js']).toContain('//# sourceMappingURL=index.js.map');
const map1 = JSON.parse(
readFileSync(join(__dirname, 'dist/esm/index.js.map'), 'utf-8'),
);
expect(map1.sources[0]).toEqual('../../src/index.ts');
const map2 = JSON.parse(
readFileSync(join(__dirname, 'dist/esm/utils/index.js.map'), 'utf-8'),
);
expect(map2.sources[0]).toEqual('../../../src/utils/index.ts');
// cjs transform by swc
expect('cjs/index.js.map' in files).toBe(true);
expect(files['cjs/index.js']).toContain('//# sourceMappingURL=index.js.map');
const map3 = JSON.parse(
readFileSync(join(__dirname, 'dist/cjs/index.js.map'), 'utf-8'),
);
expect(map3.sources[0]).toEqual('../../src/index.ts');
const map4 = JSON.parse(
readFileSync(join(__dirname, 'dist/cjs/utils/index.js.map'), 'utf-8'),
);
expect(map4.sources[0]).toEqual('../../../src/utils/index.ts');
};