Skip to content

Commit

Permalink
Merge pull request #4191 from coralproject/fix/CORL-2782-fix-gha-tests
Browse files Browse the repository at this point in the history
[CORL-2782] Separate tests into different sections to improve GHA performance
  • Loading branch information
tessalt authored Mar 29, 2023
2 parents 878c9bf + c6cb6d8 commit f4b6b07
Show file tree
Hide file tree
Showing 23 changed files with 394 additions and 92 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ jobs:
name: Lint Versions
run: npx @coralproject/package-version-lint
-
name: Run Unit Tests
run: npm run test -- --ci --runInBand --reporters=default --reporters=jest-junit
name: Run Server Unit Tests
run: npm run test:server -- --ci --runInBand --reporters=default --reporters=jest-junit
-
name: Run Client Stream Unit Tests
run: npm run test:client:stream -- --ci --runInBand --reporters=default --reporters=jest-junit
-
name: Run Client Admin Unit Tests
run: npm run test:client:admin -- --ci --runInBand --reporters=default --reporters=jest-junit
-
name: Run Client Other Unit Tests
run: npm run test:client:other -- --ci --runInBand --reporters=default --reporters=jest-junit
-
name: Build
run: npm run build
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/build-test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,17 @@ jobs:
name: Lint Versions
run: npx @coralproject/package-version-lint
-
name: Run Unit Tests
run: npm run test -- --ci --runInBand --reporters=default --reporters=jest-junit
name: Run Server Unit Tests
run: npm run test:server -- --ci --runInBand --reporters=default --reporters=jest-junit
-
name: Run Client Stream Unit Tests
run: npm run test:client:stream -- --ci --runInBand --reporters=default --reporters=jest-junit
-
name: Run Client Admin Unit Tests
run: npm run test:client:admin -- --ci --runInBand --reporters=default --reporters=jest-junit
-
name: Run Client Other Unit Tests
run: npm run test:client:other -- --ci --runInBand --reporters=default --reporters=jest-junit
-
name: Build
run: npm run build
Expand Down
5 changes: 5 additions & 0 deletions config/jest.client.admin.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
projects: [
"<rootDir>/jest/client.admin.config.js",
],
};
5 changes: 5 additions & 0 deletions config/jest.client.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
projects: [
"<rootDir>/jest/client.config.js",
],
};
5 changes: 5 additions & 0 deletions config/jest.client.other.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
projects: [
"<rootDir>/jest/client.other.config.js",
],
};
5 changes: 5 additions & 0 deletions config/jest.client.stream.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
projects: [
"<rootDir>/jest/client.stream.config.js",
],
};
5 changes: 5 additions & 0 deletions config/jest.server.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
projects: [
"<rootDir>/jest/server.config.js",
],
};
9 changes: 9 additions & 0 deletions config/jest/client.admin.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const createConfig = require("./client.baseConfig");

const baseConfig = createConfig();

module.exports = {
...baseConfig,
displayName: "client:admin",
roots: ["<rootDir>/src/core/client/admin"],
}
87 changes: 87 additions & 0 deletions config/jest/client.baseConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const path = require("path");

const createConfig = () => {
const d3Pkgs = [
"d3",
"d3-array",
"d3-axis",
"d3-brush",
"d3-chord",
"d3-color",
"d3-contour",
"d3-delaunay",
"d3-dispatch",
"d3-drag",
"d3-dsv",
"d3-ease",
"d3-fetch",
"d3-force",
"d3-format",
"d3-geo",
"d3-hierarchy",
"d3-interpolate",
"d3-path",
"d3-polygon",
"d3-quadtree",
"d3-random",
"d3-scale",
"d3-scale-chromatic",
"d3-selection",
"d3-shape",
"d3-time",
"d3-time-format",
"d3-timer",
"d3-transition",
"d3-zoom",
];

return {
displayName: "jestBaseConfig",
rootDir: "../../",
roots: ["<rootDir>/src/core/"],
collectCoverageFrom: ["**/*.{js,jsx,mjs,ts,tsx}"],
coveragePathIgnorePatterns: ["/node_modules/"],
setupFiles: [
"<rootDir>/src/core/client/test/polyfills.ts",
"<rootDir>/src/core/client/test/setup.ts",
],
setupFilesAfterEnv: ["<rootDir>/src/core/client/test/setupTestFramework.ts"],
testMatch: ["**/*.spec.{js,jsx,mjs,ts,tsx}"],
testEnvironment: "node",
testURL: "http://localhost",
transform: {
"^.+\\.jsx?$": "<rootDir>/node_modules/babel-jest",
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
"^.+\\.ftl$": "<rootDir>/config/jest/contentTransform.js",
"^(?!.*\\.(js|jsx|mjs|ts|tsx|css|json|ftl)$)":
"<rootDir>/config/jest/fileTransform.js",
},
transformIgnorePatterns: [
`[/\\\\]node_modules[/\\\\](?!(fluent|react-relay-network-modern|@coralproject/rte/lib|internmap|${d3Pkgs.join(
"|"
)})[/\\\\]).+\\.(js|jsx|mjs|ts|tsx)$`,
],
moduleNameMapper: {
"^coral-account/(.*)$": "<rootDir>/src/core/client/account/$1",
"^coral-admin/(.*)$": "<rootDir>/src/core/client/admin/$1",
"^coral-auth/(.*)$": "<rootDir>/src/core/client/auth/$1",
"^coral-count/(.*)$": "<rootDir>/src/core/client/count/$1",
"^coral-ui/(.*)$": "<rootDir>/src/core/client/ui/$1",
"^coral-stream/(.*)$": "<rootDir>/src/core/client/stream/$1",
"^coral-framework/(.*)$": "<rootDir>/src/core/client/framework/$1",
"^coral-common/(.*)$": "<rootDir>/src/core/common/$1",
"^coral-test/(.*)$": "<rootDir>/src/core/client/test/$1",
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node", "ftl"],
globals: {
"ts-jest": {
babelConfig: true,
tsConfig: path.resolve(__dirname, "../../src/core/client/tsconfig.json"),
},
},
preset: "ts-jest/presets/js-with-babel",
};
}

module.exports = createConfig;
82 changes: 4 additions & 78 deletions config/jest/client.config.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,9 @@
const path = require("path");
const createConfig = require("./client.baseConfig");

const d3Pkgs = [
"d3",
"d3-array",
"d3-axis",
"d3-brush",
"d3-chord",
"d3-color",
"d3-contour",
"d3-delaunay",
"d3-dispatch",
"d3-drag",
"d3-dsv",
"d3-ease",
"d3-fetch",
"d3-force",
"d3-format",
"d3-geo",
"d3-hierarchy",
"d3-interpolate",
"d3-path",
"d3-polygon",
"d3-quadtree",
"d3-random",
"d3-scale",
"d3-scale-chromatic",
"d3-selection",
"d3-shape",
"d3-time",
"d3-time-format",
"d3-timer",
"d3-transition",
"d3-zoom",
];
const baseConfig = createConfig();

module.exports = {
...baseConfig,
displayName: "client",
rootDir: "../../",
roots: ["<rootDir>/src/core/client"],
collectCoverageFrom: ["**/*.{js,jsx,mjs,ts,tsx}"],
coveragePathIgnorePatterns: ["/node_modules/"],
setupFiles: [
"<rootDir>/src/core/client/test/polyfills.ts",
"<rootDir>/src/core/client/test/setup.ts",
],
setupFilesAfterEnv: ["<rootDir>/src/core/client/test/setupTestFramework.ts"],
testMatch: ["**/*.spec.{js,jsx,mjs,ts,tsx}"],
testEnvironment: "node",
testURL: "http://localhost",
transform: {
"^.+\\.jsx?$": "<rootDir>/node_modules/babel-jest",
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
"^.+\\.ftl$": "<rootDir>/config/jest/contentTransform.js",
"^(?!.*\\.(js|jsx|mjs|ts|tsx|css|json|ftl)$)":
"<rootDir>/config/jest/fileTransform.js",
},
transformIgnorePatterns: [
`[/\\\\]node_modules[/\\\\](?!(fluent|react-relay-network-modern|@coralproject/rte/lib|internmap|${d3Pkgs.join(
"|"
)})[/\\\\]).+\\.(js|jsx|mjs|ts|tsx)$`,
],
moduleNameMapper: {
"^coral-account/(.*)$": "<rootDir>/src/core/client/account/$1",
"^coral-admin/(.*)$": "<rootDir>/src/core/client/admin/$1",
"^coral-auth/(.*)$": "<rootDir>/src/core/client/auth/$1",
"^coral-count/(.*)$": "<rootDir>/src/core/client/count/$1",
"^coral-ui/(.*)$": "<rootDir>/src/core/client/ui/$1",
"^coral-stream/(.*)$": "<rootDir>/src/core/client/stream/$1",
"^coral-framework/(.*)$": "<rootDir>/src/core/client/framework/$1",
"^coral-common/(.*)$": "<rootDir>/src/core/common/$1",
"^coral-test/(.*)$": "<rootDir>/src/core/client/test/$1",
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node", "ftl"],
globals: {
"ts-jest": {
babelConfig: true,
tsConfig: path.resolve(__dirname, "../../src/core/client/tsconfig.json"),
},
},
preset: "ts-jest/presets/js-with-babel",
};
}
27 changes: 27 additions & 0 deletions config/jest/client.other.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const fs = require("fs");
const path = require("path");
const createConfig = require("./client.baseConfig");

const dir = "./src/core/client";
const dirItems = fs.readdirSync(dir);
let roots = [];

const excludedRoots = ["src/core/client/stream", "src/core/client/admin"];

for (const item of dirItems) {
const fullPath = path.join(dir, item);
const stats = fs.statSync(fullPath);
if (stats.isDirectory() && !excludedRoots.includes(fullPath)) {
roots.push(fullPath);
}
}

roots = roots.map((r) => `<rootDir>/${r}`);

const baseConfig = createConfig();

module.exports = {
...baseConfig,
displayName: "client:other",
roots
}
9 changes: 9 additions & 0 deletions config/jest/client.stream.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const createConfig = require("./client.baseConfig");

const baseConfig = createConfig();

module.exports = {
...baseConfig,
displayName: "client:stream",
roots: ["<rootDir>/src/core/client/stream"],
}
15 changes: 15 additions & 0 deletions config/paths.client.admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from "fs";
import path from "path";
import appPaths from "../src/core/build/paths";

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebookincubator/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = (relativePath: string) =>
path.resolve(appDirectory, relativePath);

// config after eject: we're in ./config/
export default {
...appPaths,
appJestConfig: resolveApp("config/jest.client.admin.config.js"),
};
15 changes: 15 additions & 0 deletions config/paths.client.other.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from "fs";
import path from "path";
import appPaths from "../src/core/build/paths";

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebookincubator/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = (relativePath: string) =>
path.resolve(appDirectory, relativePath);

// config after eject: we're in ./config/
export default {
...appPaths,
appJestConfig: resolveApp("config/jest.client.other.config.js"),
};
15 changes: 15 additions & 0 deletions config/paths.client.stream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from "fs";
import path from "path";
import appPaths from "../src/core/build/paths";

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebookincubator/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = (relativePath: string) =>
path.resolve(appDirectory, relativePath);

// config after eject: we're in ./config/
export default {
...appPaths,
appJestConfig: resolveApp("config/jest.client.stream.config.js"),
};
15 changes: 15 additions & 0 deletions config/paths.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from "fs";
import path from "path";
import appPaths from "../src/core/build/paths";

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebookincubator/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = (relativePath: string) =>
path.resolve(appDirectory, relativePath);

// config after eject: we're in ./config/
export default {
...appPaths,
appJestConfig: resolveApp("config/jest.client.config.js"),
};
15 changes: 15 additions & 0 deletions config/paths.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from "fs";
import path from "path";
import appPaths from "../src/core/build/paths";

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebookincubator/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = (relativePath: string) =>
path.resolve(appDirectory, relativePath);

// config after eject: we're in ./config/
export default {
...appPaths,
appJestConfig: resolveApp("config/jest.server.config.js"),
};
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@
"start:development:withJobs": "NODE_ENV=development TS_NODE_PROJECT=./src/tsconfig.json ts-node-dev --inspect --transpile-only --no-notify -r tsconfig-paths/register --ignore-watch ./docs/ ./src/index.ts",
"start:webpackDevServer": "ts-node --transpile-only ./scripts/start.ts",
"start": "NODE_ENV=production node dist/index.js",
"test": "node --trace-warnings scripts/test.js --env=jsdom",
"test": "node --trace-warnings scripts/test.js --watch",
"test:server": "node --trace-warnings scripts/testServer.js",
"test:client:stream": "node --trace-warnings scripts/testClient.stream.js",
"test:client:admin": "node --trace-warnings scripts/testClient.admin.js",
"test:client:other": "node --trace-warnings scripts/testClient.other.js",
"test:cache": "node --trace-warnings scripts/test.cache.js --env=jsdom",
"tscheck:client": "tsc --project ./src/core/client/tsconfig.json --noEmit",
"tscheck:scripts": "tsc --project ./tsconfig.json --noEmit",
Expand Down
Loading

0 comments on commit f4b6b07

Please sign in to comment.