Skip to content

Commit ba88315

Browse files
authored
Merge pull request #232 from akd-io/feature/65-cli-make-tests-run-in-parallel
Make tests run in parallel
2 parents 4d6296c + f1faf18 commit ba88315

Some content is hidden

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

48 files changed

+519
-741
lines changed

.github/workflows/cli-ci.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,48 @@ name: "CLI - CI"
33
on: [pull_request]
44

55
jobs:
6+
get-test-files:
7+
name: "Gets all e2e Jest test files for use in a later job"
8+
9+
runs-on: ubuntu-latest
10+
11+
outputs:
12+
test-files: ${{ steps.set-test-files.outputs.files }}
13+
14+
steps:
15+
- name: "Checkout repo"
16+
uses: actions/checkout@v3
17+
18+
- name: "Set up pnpm"
19+
uses: pnpm/action-setup@v2
20+
with:
21+
version: 8
22+
23+
- name: "Set up Node 18"
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: 18
27+
cache: pnpm
28+
29+
- name: "Install dependencies"
30+
run: pnpm install
31+
32+
- name: "Get test files"
33+
id: set-test-files
34+
working-directory: packages/create-next-stack
35+
run: |
36+
echo "files=$(pnpm --silent get-e2e-test-files-array)" >> $GITHUB_OUTPUT
37+
638
build:
7-
name: "Build, lint, test - ${{ matrix.os }}"
39+
name: "Test - ${{ matrix.test-file.fileName }} - ${{ matrix.os }}"
40+
41+
needs: get-test-files
842

943
strategy:
1044
matrix:
1145
node: ["18"]
1246
os: [ubuntu-latest, windows-latest, macOS-latest]
47+
test-file: ${{ fromJSON(needs.get-test-files.outputs.test-files) }}
1348

1449
runs-on: ${{ matrix.os }}
1550

@@ -38,4 +73,5 @@ jobs:
3873
run: pnpm lint:cli
3974

4075
- name: "Test"
41-
run: pnpm test:cli
76+
working-directory: packages/create-next-stack
77+
run: pnpm jest-e2e:ci ${{ matrix.test-file.filePath }}

packages/create-next-stack/jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
module.exports = {
44
preset: "ts-jest",
55
testEnvironment: "node",
6-
testPathIgnorePatterns: ["/node_modules/", "/lib/", "/src/tests/"],
6+
testPathIgnorePatterns: ["/node_modules/", "/lib/"],
7+
setupFilesAfterEnv: ["./override-jest-console.js"],
78
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Overrides the default Jest console with the Node.js console.
2+
global.console = require("console")

packages/create-next-stack/package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,20 @@
5050
"check-types": "tsc --noEmit",
5151
"check-types:watch": "tsc --noEmit --watch",
5252
"build": "rimraf lib && tsc --build",
53-
"build:watch": "rimraf lib && tsc --build --watch",
54-
"clean": "rimraf lib && pnpm run clean-tests-dir",
53+
"build:watch": "pnpm build --watch",
54+
"clean": "rimraf lib && pnpm clean-tests-dir",
5555
"clean-tests-dir": "ts-node src/tests/e2e/clean-tests-dir.ts",
56-
"test": "pnpm build && pnpm run jest && ts-node src/tests/e2e/test.ts",
56+
"test": "pnpm build && pnpm jest-unit && pnpm jest-e2e",
5757
"jest": "jest",
58-
"jest:watch": "jest --watch",
58+
"jest-unit": "jest src/main/",
59+
"jest-unit:ci": "jest --ci src/main/",
60+
"jest-unit:watch": "pnpm jest-unit --watch",
61+
"get-e2e-test-files-array": "jest --listTests src/tests/e2e/ | ts-node src/scripts/file-list-to-array.ts",
62+
"jest-e2e": "jest --runInBand src/tests/e2e/",
63+
"jest-e2e:watch": "pnpm jest-e2e --watch",
64+
"jest-e2e:single": "jest --runInBand",
65+
"jest-e2e:ci": "jest --runInBand --ci",
5966
"test:manual": "pnpm build && ts-node src/tests/e2e/test-manual.ts --debug",
60-
"test:small": "pnpm build && ts-node src/tests/e2e/test-manual.ts --debug --package-manager=pnpm --styling=css-modules",
61-
"test:large": "pnpm build && ts-node src/tests/e2e/test-manual.ts --debug --package-manager=pnpm --styling=emotion --react-hook-form --formik --prettier --formatting-pre-commit-hook --chakra --framer-motion --github-actions",
6267
"test:cna": "pnpm build && ts-node src/tests/e2e/test-live-cna.ts",
6368
"test:cns": "pnpm build && ts-node src/tests/e2e/test-live-cns.ts",
6469
"test:raw": "pnpm build && ./bin/dev",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { resolve } from "path"
2+
3+
/*
4+
This script reads each line of stdin and outputs a JSON array of the lines.
5+
This is useful for passing a list of files to a command.
6+
Example usage: `ls | node file-list-to-array.ts`
7+
*/
8+
9+
let input = ""
10+
process.stdin.on("data", (data) => {
11+
input += data.toString()
12+
})
13+
process.stdin.on("end", () => {
14+
const filePaths = input.split("\n").filter(Boolean)
15+
const files = filePaths.map((filePath) => ({
16+
filePath: filePath.replace(resolve(process.cwd()) + "/", ""),
17+
fileName: filePath.split("/").pop()?.split(".")[0] || filePath,
18+
}))
19+
console.log(JSON.stringify(files))
20+
})

packages/create-next-stack/src/tests/e2e/helpers/log-test-meta.ts

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

packages/create-next-stack/src/tests/e2e/helpers/minutes-to-milliseconds.ts

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

packages/create-next-stack/src/tests/e2e/helpers/check-formatting-linting-build.ts renamed to packages/create-next-stack/src/tests/e2e/helpers/perform-final-checks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Options } from "execa"
22
import { runCommand } from "../../../main/helpers/run-command"
33
import { logTestInfo } from "../test-logging"
44

5-
export const performE2eChecks = async (
5+
export const performFinalChecks = async (
66
runDirectory: string,
77
args: string[]
88
): Promise<void> => {

packages/create-next-stack/src/tests/e2e/helpers/prepare-e2e-test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ import path from "path"
33
import { v4 as uuidv4 } from "uuid"
44
import { makeDirectory } from "../../../main/helpers/io"
55
import { logTestInfo } from "../test-logging"
6+
import { setGitNameAndEmailIfMissing } from "./set-git-name-and-email"
67

7-
export const prepareE2eTest = async (
8-
createNextStackDir: string
9-
): Promise<{
8+
/**
9+
* Prepare an e2e test by creating a directory to run the CLI in.
10+
*
11+
* @returns The path to the CLI and the directory where the CLI was run.
12+
*/
13+
export const prepareE2eTest = async (): Promise<{
1014
pathToCLI: string
1115
runDirectory: string
1216
}> => {
17+
process.env["TEST"] = "true"
18+
await setGitNameAndEmailIfMissing()
19+
20+
const createNextStackDir = path.resolve(process.cwd())
21+
1322
const testRunId = uuidv4()
1423

1524
const runDirectory = path.resolve(

packages/create-next-stack/src/tests/e2e/helpers/set-git-name-and-email.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { runCommand } from "../../../main/helpers/run-command"
22
import { logTestError, logTestInfo } from "../test-logging"
33

4-
export const setGitNameAndEmail = async (): Promise<void> => {
4+
/**
5+
* If not set already, sets Git name and email so `git commit` doesn't fail during create-next-app
6+
* Missing git name and email is mainly a problem in CI/CD environments
7+
*/
8+
export const setGitNameAndEmailIfMissing = async (): Promise<void> => {
59
try {
610
await runCommand("git", ["config", "--global", "user.name"])
711
.then((result) => {

0 commit comments

Comments
 (0)