Skip to content

Commit 3e23b88

Browse files
authored
test: use karton for e2e tests (#627)
Use external package to handle e2e tests to simplify code base
1 parent fb3fee8 commit 3e23b88

File tree

132 files changed

+1223
-215508
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+1223
-215508
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/lib/**
2+
/test/e2e/fixtures/**

.github/workflows/main.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v1
8-
8+
99
- name: Setup node
1010
uses: actions/setup-node@v1
1111
with:
@@ -44,7 +44,7 @@ jobs:
4444
os: [ubuntu-latest, macos-latest, windows-latest]
4545
steps:
4646
- uses: actions/checkout@v1
47-
47+
4848
- name: Setup node
4949
uses: actions/setup-node@v1
5050
with:
@@ -61,7 +61,13 @@ jobs:
6161
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
6262
restore-keys: |
6363
${{ runner.os }}-yarn-
64-
64+
65+
- name: Locks cache
66+
uses: actions/cache@v2
67+
with:
68+
path: test/e2e/__locks__
69+
key: ${{ runner.os }}-locks
70+
6571
- name: Install dependencies
6672
run: yarn install --frozen-lockfile
6773

@@ -76,7 +82,7 @@ jobs:
7682

7783
- name: Run e2e tests
7884
run: yarn test:e2e
79-
85+
8086
release:
8187
runs-on: ubuntu-latest
8288
env:
@@ -86,7 +92,7 @@ jobs:
8692
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/alpha' || github.ref == 'refs/heads/beta')
8793
steps:
8894
- uses: actions/checkout@v1
89-
95+
9096
- name: Setup node
9197
uses: actions/setup-node@v1
9298
with:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ lib
77
# Package archive used by e2e tests
88
fork-ts-checker-webpack-plugin-0.0.0-semantic-release.tgz
99

10+
# E2E tests lock file cache dir
11+
__locks__
12+
1013
# Coverage directory used by tools like istanbul
1114
coverage
1215

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"jest": "^26.5.3",
106106
"jest-circus": "^26.5.3",
107107
"jest-environment-node": "^26.5.2",
108+
"karton": "^0.4.1",
108109
"lint-staged": "^10.4.2",
109110
"mock-fs": "^4.13.0",
110111
"prettier": "^2.1.2",

test/e2e/OutOfMemoryAndCosmiconfig.spec.ts

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,23 @@
1-
import { join } from 'path';
2-
import { createSandbox, Sandbox } from './sandbox/Sandbox';
3-
import { readFixture } from './sandbox/Fixture';
4-
import { createGenericProcessDriver } from './sandbox/GenericProcessDriver';
5-
import { FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION } from './sandbox/Plugin';
1+
import path from 'path';
2+
import { createProcessDriver } from 'karton';
63

74
describe('ForkTsCheckerWebpackPlugin Out Of Memory and Cosmiconfig', () => {
8-
let sandbox: Sandbox;
9-
10-
beforeAll(async () => {
11-
sandbox = await createSandbox();
12-
});
13-
14-
beforeEach(async () => {
15-
await sandbox.reset();
16-
});
17-
18-
afterAll(async () => {
19-
await sandbox.cleanup();
20-
});
21-
225
it.each([
236
{ async: false, webpack: '4.0.0' },
247
{ async: true, webpack: '^4.0.0' },
258
{ async: false, webpack: '^5.0.0' },
269
{ async: true, webpack: '^5.0.0' },
2710
])('handles out of memory for %p', async ({ async, webpack }) => {
28-
await sandbox.load([
29-
await readFixture(join(__dirname, 'fixtures/environment/typescript-basic.fixture'), {
30-
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION: JSON.stringify(
31-
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION
32-
),
33-
TS_LOADER_VERSION: JSON.stringify('^5.0.0'),
34-
TYPESCRIPT_VERSION: JSON.stringify('~3.8.0'),
35-
WEBPACK_VERSION: JSON.stringify(webpack),
36-
WEBPACK_CLI_VERSION: JSON.stringify('^3.3.11'),
37-
WEBPACK_DEV_SERVER_VERSION: JSON.stringify('^3.10.3'),
38-
ASYNC: JSON.stringify(async),
39-
}),
40-
await readFixture(join(__dirname, 'fixtures/implementation/typescript-basic.fixture')),
41-
]);
11+
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));
12+
await sandbox.install('yarn', { webpack });
13+
await sandbox.patch('webpack.config.js', 'async: false,', `async: ${JSON.stringify(async)},`);
4214

4315
await sandbox.write(
4416
'fork-ts-checker.config.js',
4517
`module.exports = { typescript: { memoryLimit: 10 } };`
4618
);
4719

48-
const driver = createGenericProcessDriver(sandbox.spawn('npm run webpack-dev-server'));
20+
const driver = createProcessDriver(sandbox.spawn('npm run webpack-dev-server'));
4921

5022
// we should see an error message about out of memory
5123
await driver.waitForStderrIncludes(

test/e2e/TypeDefinitions.spec.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,9 @@
1-
import { join } from 'path';
2-
import { createSandbox, Sandbox } from './sandbox/Sandbox';
3-
import { readFixture } from './sandbox/Fixture';
4-
import { FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION } from './sandbox/Plugin';
1+
import path from 'path';
52

63
describe('Type Definitions', () => {
7-
let sandbox: Sandbox;
8-
9-
beforeAll(async () => {
10-
sandbox = await createSandbox();
11-
});
12-
13-
beforeEach(async () => {
14-
await sandbox.reset();
15-
});
16-
17-
afterAll(async () => {
18-
await sandbox.cleanup();
19-
});
20-
214
it('provides valid type definitions', async () => {
22-
await sandbox.load(
23-
await readFixture(join(__dirname, 'fixtures/type-definitions.fixture'), {
24-
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION: JSON.stringify(
25-
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION
26-
),
27-
})
28-
);
5+
await sandbox.load(path.join(__dirname, 'fixtures/type-definitions'));
6+
await sandbox.install('yarn', {});
297

308
expect(await sandbox.exec('npm run tsc').catch((error) => error)).toContain(
319
"webpack.config.ts(7,7): error TS2322: Type 'string' is not assignable to type 'boolean | undefined'."
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import path from 'path';
2+
import {
3+
createWebpackDevServerDriver,
4+
WebpackDevServerDriver,
5+
} from './driver/WebpackDevServerDriver';
6+
7+
describe('TypeScript Configuration', () => {
8+
it.each([
9+
{ async: true, webpack: '~4.0.0', typescript: '2.7.1', 'ts-loader': '^5.0.0' },
10+
{ async: false, webpack: '^4.0.0', typescript: '~3.0.0', 'ts-loader': '^6.0.0' },
11+
{ async: true, webpack: '^5.0.0', typescript: '~3.7.0', 'ts-loader': '^7.0.0' },
12+
{ async: false, webpack: '^5.0.0', typescript: '~3.8.0', 'ts-loader': '^6.0.0' },
13+
])(
14+
'change in the tsconfig.json affects compilation for %p',
15+
async ({ async, ...dependencies }) => {
16+
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));
17+
await sandbox.install('yarn', { ...dependencies });
18+
await sandbox.patch('webpack.config.js', 'async: false,', `async: ${JSON.stringify(async)},`);
19+
20+
const driver = createWebpackDevServerDriver(
21+
sandbox.spawn('npm run webpack-dev-server'),
22+
async
23+
);
24+
25+
// first compilation is successful
26+
await driver.waitForNoErrors();
27+
28+
// change available libraries
29+
await sandbox.patch('tsconfig.json', '"lib": ["ES6", "DOM"]', '"lib": ["ES6"],');
30+
31+
const errors = await driver.waitForErrors();
32+
expect(errors.length).toBeGreaterThan(0);
33+
34+
// revert the change
35+
await sandbox.patch('tsconfig.json', '"lib": ["ES6"],', '"lib": ["DOM", "ES6"]');
36+
37+
await driver.waitForNoErrors();
38+
}
39+
);
40+
41+
it.each([
42+
{ typescript: '2.7.1' },
43+
{ typescript: '~3.0.0' },
44+
{ typescript: '~3.6.0' },
45+
{ typescript: '^3.8.0' },
46+
])('reports errors because of the misconfiguration', async (dependencies) => {
47+
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));
48+
await sandbox.install('yarn', { ...dependencies });
49+
50+
let driver: WebpackDevServerDriver;
51+
let errors: string[];
52+
53+
await sandbox.write(
54+
'fork-ts-checker.config.js',
55+
'module.exports = { typescript: { configOverwrite: { compilerOptions: { target: "ES3", lib: ["ES3"] } } } };'
56+
);
57+
58+
driver = createWebpackDevServerDriver(sandbox.spawn('npm run webpack-dev-server'), false);
59+
errors = await driver.waitForErrors();
60+
expect(errors.length).toBeGreaterThan(0);
61+
await sandbox.kill(driver.process);
62+
63+
await sandbox.write(
64+
'fork-ts-checker.config.js',
65+
'module.exports = { typescript: { configOverwrite: { include: [] } } };'
66+
);
67+
68+
driver = createWebpackDevServerDriver(sandbox.spawn('npm run webpack-dev-server'), false);
69+
errors = await driver.waitForErrors();
70+
expect(errors.length).toBeGreaterThan(0);
71+
await sandbox.kill(driver.process);
72+
});
73+
});

test/e2e/TypeScriptConfigurationChange.spec.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

test/e2e/TypeScriptConfigurationOverwrite.spec.ts

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)