Skip to content

Commit

Permalink
test: add setup-e2e-test.ts to avoid repeating setup codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl committed Aug 1, 2024
1 parent 57ce90a commit 61727ea
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 61 deletions.
16 changes: 1 addition & 15 deletions jest-cjs.config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import { existsSync } from 'node:fs';
import path from 'node:path';

import type { Config } from '@jest/types';
import { sync as spawnSync } from 'execa';
import { sync as globSync } from 'glob';

const e2eFoldersToInstallDeps = globSync('e2e/*')
.map((folderPath) => path.join(process.cwd(), folderPath))
.filter((folderPath) => existsSync(path.join(folderPath, 'package.json')));

e2eFoldersToInstallDeps.forEach((folderPath) => {
spawnSync('yarn', ['install'], {
cwd: folderPath,
});
});

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

Expand Down
16 changes: 1 addition & 15 deletions jest-esm.config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import { existsSync } from 'node:fs';
import path from 'node:path';

import type { Config } from '@jest/types';
import { sync as spawnSync } from 'execa';
import { sync as globSync } from 'glob';

const e2eFoldersToInstallDeps = globSync('e2e/*')
.map((folderPath) => path.join(process.cwd(), folderPath))
.filter((folderPath) => existsSync(path.join(folderPath, 'package.json')));

e2eFoldersToInstallDeps.forEach((folderPath) => {
spawnSync('yarn', ['install'], {
cwd: folderPath,
});
});

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

Expand Down
16 changes: 1 addition & 15 deletions jest-transpile-cjs.config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import { existsSync } from 'node:fs';
import path from 'node:path';

import type { Config } from '@jest/types';
import { sync as spawnSync } from 'execa';
import { sync as globSync } from 'glob';

const e2eFoldersToInstallDeps = globSync('e2e/*')
.map((folderPath) => path.join(process.cwd(), folderPath))
.filter((folderPath) => existsSync(path.join(folderPath, 'package.json')));

e2eFoldersToInstallDeps.forEach((folderPath) => {
spawnSync('yarn', ['install'], {
cwd: folderPath,
});
});

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

Expand Down
16 changes: 1 addition & 15 deletions jest-transpile-esm.config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import { existsSync } from 'node:fs';
import path from 'node:path';

import type { Config } from '@jest/types';
import { sync as spawnSync } from 'execa';
import { sync as globSync } from 'glob';

const e2eFoldersToInstallDeps = globSync('e2e/*')
.map((folderPath) => path.join(process.cwd(), folderPath))
.filter((folderPath) => existsSync(path.join(folderPath, 'package.json')));

e2eFoldersToInstallDeps.forEach((folderPath) => {
spawnSync('yarn', ['install'], {
cwd: folderPath,
});
});

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

Expand Down
19 changes: 19 additions & 0 deletions setup-e2e-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { existsSync } from 'node:fs';
import path from 'node:path';

import { sync as spawnSync } from 'execa';
import { sync as globSync } from 'glob';

const globalSetup = async () => {
const e2eFoldersToInstallDeps = globSync('e2e/*')
.map((folderPath) => path.join(process.cwd(), folderPath))
.filter((folderPath) => existsSync(path.join(folderPath, 'package.json')));

e2eFoldersToInstallDeps.forEach((folderPath) => {
spawnSync('yarn', ['install'], {
cwd: folderPath,
});
});
};

export default globalSetup;
3 changes: 2 additions & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"files": [
".eslintrc.js"
],
"include": ["src", "presets", "website", "*.js", "scripts", "examples", "e2e", "*.config.ts"]
"include": ["**/*"],
"exclude": ["build", ".yarn"]
}

0 comments on commit 61727ea

Please sign in to comment.