forked from recharts/recharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildOutput.test.ts
86 lines (74 loc) · 2.89 KB
/
buildOutput.test.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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { existsSync } from 'fs';
import { describe, it, expect } from 'vitest';
import { globSync } from 'glob';
import packageJson from '../package.json';
/**
* If you see this test failing it means the build output has changed.
*
* If that is intentional - for example, you added a new file, or a new Chart type, all good!
* Change the test and run build again.
* If the test failure is in snapshots, then update the snapshots by running this command:
*
* npm run test-build-output -- --update
*
* If you did not expect the output to change, then consider going back and review your changes.
* We do not want to npm publish too many files, or not enough files.
*/
describe('expected folder structure', () => {
describe('package.json', () => {
it('should include output files', () => {
expect(packageJson.files).toHaveLength(5);
expect(packageJson.files).toContain('*.md');
expect(packageJson.files).toContain('types');
expect(packageJson.files).toContain('es6');
expect(packageJson.files).toContain('umd');
expect(packageJson.files).toContain('lib');
});
it('should point to a main file', () => {
expect(packageJson.main).toEqual('lib/index.js');
expect(existsSync(`./${packageJson.main}`)).toBe(true);
});
it('should point to a main module file', () => {
expect(packageJson.module).toEqual('es6/index.js');
expect(existsSync(`./${packageJson.module}`)).toBe(true);
});
it('should point to a jsnext:main file', () => {
expect(packageJson['jsnext:main']).toEqual('es6/index.js');
expect(existsSync(`./${packageJson['jsnext:main']}`)).toBe(true);
});
it('should point to a types file', () => {
expect(packageJson.types).toEqual('types/index.d.ts');
expect(existsSync(`./${packageJson.types}`)).toBe(true);
});
});
async function checkFolderOutput(folder: string, snapshot: string) {
return expect(globSync(folder, { dot: true, platform: 'linux' }).sort()).toMatchFileSnapshot(
`./snapshots/${snapshot}.txt`,
);
}
describe('types folder output', () => {
it('should have expected files and no more', async () => {
await checkFolderOutput('types/**/*', 'typesFiles');
});
});
describe('es6 folder output', () => {
it('should have expected files and no more', async () => {
await checkFolderOutput('es6/**/*', 'es6Files');
});
});
describe('markdown files output', () => {
it('should have expected files and no more', async () => {
await checkFolderOutput('*.md', 'markdownFiles');
});
});
describe('umd folder output', () => {
it('should have expected files and no more', async () => {
await checkFolderOutput('umd/**/*', 'umdFiles');
});
});
describe('lib folder output', () => {
it('should have expected files and no more', async () => {
await checkFolderOutput('lib/**/*', 'libFiles');
});
});
});