-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathwebpack-bundle.test.ts
75 lines (65 loc) · 2.91 KB
/
webpack-bundle.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
import { readFileSync } from 'fs';
import { join } from 'path';
import { getCommandOutput, getEntrypoints, callSerializer, getParams } from './helpers.js';
// @ts-ignore
import { toMatchSpecificSnapshot, addSerializer } from './specific-snapshot.cjs';
expect.extend({
toMatchExtendedSpecificSnapshot(received, snapshotFile) {
return toMatchSpecificSnapshot.call(this, received + 1, snapshotFile);
},
});
callSerializer();
describe('webpack-bundle test', () => {
test('bundle check', () => {
const folderPath = join(__dirname, 'webpack-bundle/bundle');
const entryPoint = getEntrypoints(folderPath);
const args = getParams('../../../dist/bundle.js', 'bundle', ['-o=/tmp/null', ...entryPoint]);
const result = getCommandOutput(args, folderPath);
(<any>expect(result)).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js'));
});
test('lint check', () => {
const folderPath = join(__dirname, 'webpack-bundle/lint');
const entryPoint = getEntrypoints(folderPath);
const args = getParams('../../../dist/bundle.js', 'lint', [...entryPoint]);
const result = getCommandOutput(args, folderPath);
(<any>expect(result)).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js'));
});
test('bundle-workflows', () => {
const folderPath = join(__dirname, 'webpack-bundle/bundle-workflows');
const entryPoint = getEntrypoints(folderPath);
const args = getParams('../../../dist/bundle.js', 'bundle', [
'--extends=redocly-registry',
`--metafile=./metafile.json`,
`-o=./bundle.yaml`,
...entryPoint,
]);
const result = getCommandOutput(args, folderPath);
const metaFile = readFileSync(`${folderPath}/metafile.json`, 'utf-8');
const bundleFile = readFileSync(`${folderPath}/bundle.yaml`, 'utf-8');
(<any>expect(metaFile)).toMatchSpecificSnapshot(join(folderPath, 'meta-snapshot.js'));
(<any>expect(bundleFile)).toMatchSpecificSnapshot(join(folderPath, 'bundle-snapshot.js'));
(<any>expect(result)).toMatchSpecificSnapshot(join(folderPath, 'result-snapshot.js'));
});
test('lint-workflows', () => {
const folderPath = join(__dirname, 'webpack-bundle/lint-workflows');
const entryPoint = getEntrypoints(folderPath);
const args = getParams('../../../dist/bundle.js', 'lint', [
'--format=json',
'--lint-config=off',
...entryPoint,
]);
const result = getCommandOutput(args, folderPath);
(<any>expect(result)).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js'));
});
test('lint-workflows-fail', () => {
const folderPath = join(__dirname, 'webpack-bundle/lint-workflows-fail');
const entryPoint = getEntrypoints(folderPath);
const args = getParams('../../../dist/bundle.js', 'lint', [
'--format=json',
'--lint-config=off',
...entryPoint,
]);
const result = getCommandOutput(args, folderPath);
(<any>expect(result)).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js'));
});
});