Skip to content

Commit 61727ea

Browse files
committed
test: add setup-e2e-test.ts to avoid repeating setup codes
1 parent 57ce90a commit 61727ea

File tree

6 files changed

+25
-61
lines changed

6 files changed

+25
-61
lines changed

jest-cjs.config.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
import { existsSync } from 'node:fs';
2-
import path from 'node:path';
3-
41
import type { Config } from '@jest/types';
5-
import { sync as spawnSync } from 'execa';
6-
import { sync as globSync } from 'glob';
7-
8-
const e2eFoldersToInstallDeps = globSync('e2e/*')
9-
.map((folderPath) => path.join(process.cwd(), folderPath))
10-
.filter((folderPath) => existsSync(path.join(folderPath, 'package.json')));
11-
12-
e2eFoldersToInstallDeps.forEach((folderPath) => {
13-
spawnSync('yarn', ['install'], {
14-
cwd: folderPath,
15-
});
16-
});
172

183
const config: Config.InitialOptions = {
4+
globalSetup: './setup-e2e-test.ts',
195
projects: ['e2e/**/jest-cjs.config.ts'],
206
};
217

jest-esm.config.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
import { existsSync } from 'node:fs';
2-
import path from 'node:path';
3-
41
import type { Config } from '@jest/types';
5-
import { sync as spawnSync } from 'execa';
6-
import { sync as globSync } from 'glob';
7-
8-
const e2eFoldersToInstallDeps = globSync('e2e/*')
9-
.map((folderPath) => path.join(process.cwd(), folderPath))
10-
.filter((folderPath) => existsSync(path.join(folderPath, 'package.json')));
11-
12-
e2eFoldersToInstallDeps.forEach((folderPath) => {
13-
spawnSync('yarn', ['install'], {
14-
cwd: folderPath,
15-
});
16-
});
172

183
const config: Config.InitialOptions = {
4+
globalSetup: './setup-e2e-test.ts',
195
projects: ['e2e/**/jest-esm.config.ts'],
206
};
217

jest-transpile-cjs.config.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
import { existsSync } from 'node:fs';
2-
import path from 'node:path';
3-
41
import type { Config } from '@jest/types';
5-
import { sync as spawnSync } from 'execa';
6-
import { sync as globSync } from 'glob';
7-
8-
const e2eFoldersToInstallDeps = globSync('e2e/*')
9-
.map((folderPath) => path.join(process.cwd(), folderPath))
10-
.filter((folderPath) => existsSync(path.join(folderPath, 'package.json')));
11-
12-
e2eFoldersToInstallDeps.forEach((folderPath) => {
13-
spawnSync('yarn', ['install'], {
14-
cwd: folderPath,
15-
});
16-
});
172

183
const config: Config.InitialOptions = {
4+
globalSetup: './setup-e2e-test.ts',
195
projects: ['jest-src.config.ts', 'e2e/**/jest-transpile-cjs.config.ts'],
206
};
217

jest-transpile-esm.config.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
import { existsSync } from 'node:fs';
2-
import path from 'node:path';
3-
41
import type { Config } from '@jest/types';
5-
import { sync as spawnSync } from 'execa';
6-
import { sync as globSync } from 'glob';
7-
8-
const e2eFoldersToInstallDeps = globSync('e2e/*')
9-
.map((folderPath) => path.join(process.cwd(), folderPath))
10-
.filter((folderPath) => existsSync(path.join(folderPath, 'package.json')));
11-
12-
e2eFoldersToInstallDeps.forEach((folderPath) => {
13-
spawnSync('yarn', ['install'], {
14-
cwd: folderPath,
15-
});
16-
});
172

183
const config: Config.InitialOptions = {
4+
globalSetup: './setup-e2e-test.ts',
195
projects: ['e2e/**/jest-transpile-esm.config.ts'],
206
};
217

setup-e2e-test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { existsSync } from 'node:fs';
2+
import path from 'node:path';
3+
4+
import { sync as spawnSync } from 'execa';
5+
import { sync as globSync } from 'glob';
6+
7+
const globalSetup = async () => {
8+
const e2eFoldersToInstallDeps = globSync('e2e/*')
9+
.map((folderPath) => path.join(process.cwd(), folderPath))
10+
.filter((folderPath) => existsSync(path.join(folderPath, 'package.json')));
11+
12+
e2eFoldersToInstallDeps.forEach((folderPath) => {
13+
spawnSync('yarn', ['install'], {
14+
cwd: folderPath,
15+
});
16+
});
17+
};
18+
19+
export default globalSetup;

tsconfig.eslint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"files": [
44
".eslintrc.js"
55
],
6-
"include": ["src", "presets", "website", "*.js", "scripts", "examples", "e2e", "*.config.ts"]
6+
"include": ["**/*"],
7+
"exclude": ["build", ".yarn"]
78
}

0 commit comments

Comments
 (0)