Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit 058a3e3

Browse files
committed
[jest] Run Jest integration tests in child process
This reworks the Jest integration tests to match the Cypress integration tests: each test is run in its own child process, and stdout/stderr are captured. This approach avoids the need for brittle mocking and prevents tests from interfering with each other.
1 parent 7e4a40f commit 058a3e3

52 files changed

Lines changed: 2376 additions & 2705 deletions

Some content is hidden

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

.github/workflows/ci.yaml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ jobs:
153153
mv package-new.json package.json
154154
yarn install --no-immutable
155155
156-
- name: Build test dependencies
157-
run: yarn build:plugins-common && yarn build:cypress-tests
158-
159156
- name: Set Cypress version
160157
env:
161158
CYPRESS_INSTALL_BINARY: "0"
@@ -166,6 +163,9 @@ jobs:
166163
- name: Install Cypress binary
167164
run: yarn workspace cypress-integration exec cypress install
168165

166+
- name: Build test dependencies
167+
run: yarn build:plugins-common && yarn build:test-common && yarn build:cypress-tests
168+
169169
- name: Test
170170
env:
171171
# Enable debug logs within the Jest tests that run Cypress. WARNING: these are very
@@ -261,9 +261,6 @@ jobs:
261261
mv package-new.json package.json
262262
yarn install --no-immutable
263263
264-
- name: Build test dependencies
265-
run: yarn build:plugins-common && yarn build:cypress-tests
266-
267264
- name: Set Cypress version
268265
env:
269266
CYPRESS_INSTALL_BINARY: "0"
@@ -274,6 +271,9 @@ jobs:
274271
- name: Install Cypress binary
275272
run: yarn workspace cypress-integration exec cypress install
276273

274+
- name: Build test dependencies
275+
run: yarn build:plugins-common && yarn build:test-common && yarn build:cypress-tests
276+
277277
- name: Test
278278
env:
279279
# Enable debug logs within the Jest tests that run Cypress. WARNING: these are very
@@ -379,9 +379,18 @@ jobs:
379379
if: ${{ startsWith(matrix.jest, '25.') }}
380380
run: yarn set resolution "chalk@npm:^3.0.0 || ^4.0.0" 3.0
381381

382+
- name: Build test dependencies
383+
run: yarn build:plugins-common && yarn build:test-common
384+
382385
- name: Test
383386
env:
384-
DEBUG: unflakable:*
387+
# Enable debug logs within the jest-plugin/test/integration Jest tests that invoke Jest
388+
# on the jest-plugin/test/integration-input test cases. WARNING: these are very verbose
389+
# but are useful for seeing the raw chalk terminal codes.
390+
# DEBUG: unflakable:*
391+
392+
# Enable debug logs within the Jest plugin.
393+
TEST_DEBUG: "unflakable:*"
385394
run: |
386395
if [ "${{ github.repository }}" == "unflakable/unflakable-javascript" ]; then
387396
export UNFLAKABLE_SUITE_ID=29KWCuK12VnU7pkpvWgrGS0woAX

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
"build:jest-plugin": "yarn workspace @unflakable/jest-plugin build",
3333
"build:plugins-common": "yarn workspace @unflakable/plugins-common build",
3434
"typecheck:scripts": "tsc --noEmit --types node -p scripts",
35-
"build:tests": "yarn build:cypress-tests && yarn typecheck:jest-tests",
36-
"build:cypress-tests": "yarn workspace cypress-integration-common build && yarn workspace cypress-integration typecheck && yarn workspace cypress-integration-input typecheck && yarn workspace cypress-integration-input-esm typecheck",
35+
"build:test-common": "yarn workspace unflakable-test-common build",
36+
"build:tests": "yarn build:test-common && yarn build:cypress-tests && yarn typecheck:jest-tests",
37+
"build:cypress-tests": "yarn workspace cypress-integration typecheck && yarn workspace cypress-integration-input typecheck && yarn workspace cypress-integration-input-esm typecheck",
3738
"typecheck:jest-tests": "yarn workspace jest-integration typecheck && yarn workspace jest-integration-input typecheck",
3839
"lint": "eslint .",
3940
"prettier": "prettier --write .",
@@ -44,7 +45,6 @@
4445
"workspaces": [
4546
"packages/*",
4647
"packages/*/test/integration",
47-
"packages/*/test/integration-common",
4848
"packages/*/test/integration-input",
4949
"packages/*/test/integration-input-esm",
5050
"packages/*/test/integration-input-manual"

packages/cypress-plugin/test/integration-common/tsconfig.json

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

packages/cypress-plugin/test/integration-input-esm/cypress-config.cjs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// Copyright (c) 2023 Developer Innovations, LLC
22

3-
const {
4-
registerSimpleGitMock,
5-
} = require("cypress-integration-common/dist/git");
3+
const { registerSimpleGitMock } = require("unflakable-test-common/dist/git");
64
const {
75
registerCosmiconfigMock,
8-
} = require("cypress-integration-common/dist/config");
6+
} = require("unflakable-test-common/dist/config");
97

108
module.exports = {
119
/**

packages/cypress-plugin/test/integration-input-esm/cypress-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import { openDevToolsOnLaunch } from "./config-js/devtools.js";
44
import { registerTasks } from "./config-js/tasks.js";
55
import webpackConfig from "./config-js/webpack.js";
6-
import { registerSimpleGitMock } from "cypress-integration-common/dist/git.js";
7-
import { registerCosmiconfigMock } from "cypress-integration-common/dist/config.js";
6+
import { registerSimpleGitMock } from "unflakable-test-common/dist/git.js";
7+
import { registerCosmiconfigMock } from "unflakable-test-common/dist/config.js";
88

99
/**
1010
* @type {Cypress.ConfigOptions}

packages/cypress-plugin/test/integration-input-esm/cypress.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { defineConfig } from "cypress";
66
import * as devtools from "./config/devtools.js";
77
import { registerTasks } from "./config/tasks.js";
88
import webpackConfig from "./config/webpack.js";
9-
import { registerSimpleGitMock } from "cypress-integration-common/dist/git.js";
10-
import { registerCosmiconfigMock } from "cypress-integration-common/dist/config.js";
9+
import { registerSimpleGitMock } from "unflakable-test-common/dist/git.js";
10+
import { registerCosmiconfigMock } from "unflakable-test-common/dist/config.js";
1111

1212
export default defineConfig({
1313
component: {

packages/cypress-plugin/test/integration-input-esm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
"@types/react-dom": "^18.2.4",
99
"@unflakable/cypress-plugin": "workspace:^",
1010
"cypress": "10 - 12",
11-
"cypress-integration-common": "workspace:^",
1211
"mocha": "=7.0.1",
1312
"mocha-junit-reporter": "^2.2.0",
1413
"process": "^0.11.10",
1514
"react": "^18.2.0",
1615
"react-dom": "^18.2.0",
1716
"ts-loader": "^9.4.3",
1817
"typescript": "^4.9.5",
18+
"unflakable-test-common": "workspace:^",
1919
"webpack": "^5.84.1"
2020
},
2121
"scripts": {

packages/cypress-plugin/test/integration-input-manual/cypress-config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import devtools from "./config/devtools.js";
44
import tasks from "./config/tasks.js";
55
import webpackConfig from "./config/webpack.js";
6-
import { registerSimpleGitMock } from "cypress-integration-common/dist/git.js";
7-
import { registerCosmiconfigMock } from "cypress-integration-common/dist/config.js";
6+
import { registerSimpleGitMock } from "unflakable-test-common/dist/git.js";
7+
import { registerCosmiconfigMock } from "unflakable-test-common/dist/config.js";
88
import { registerUnflakable } from "@unflakable/cypress-plugin";
99

1010
/**

packages/cypress-plugin/test/integration-input-manual/cypress.config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
const { openDevToolsOnLaunch } = require("./config/devtools");
44
const { registerTasks } = require("./config/tasks");
55
const webpackConfig = require("./config/webpack");
6-
const {
7-
registerSimpleGitMock,
8-
} = require("cypress-integration-common/dist/git");
6+
const { registerSimpleGitMock } = require("unflakable-test-common/dist/git");
97
const {
108
registerCosmiconfigMock,
11-
} = require("cypress-integration-common/dist/config");
9+
} = require("unflakable-test-common/dist/config");
1210

1311
const { registerUnflakable } = require("@unflakable/cypress-plugin");
1412

packages/cypress-plugin/test/integration-input-manual/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"@types/react-dom": "^18.2.4",
1111
"@unflakable/cypress-plugin": "workspace:^",
1212
"cypress": "10 - 12",
13-
"cypress-integration-common": "workspace:^",
1413
"cypress-multi-reporters": "^1.6.3",
1514
"mocha": "=7.0.1",
1615
"mocha-junit-reporter": "^2.2.0",
@@ -19,6 +18,7 @@
1918
"react-dom": "^18.2.0",
2019
"ts-loader": "^9.4.3",
2120
"typescript": "^4.9.5",
21+
"unflakable-test-common": "workspace:^",
2222
"webpack": "^5.84.1"
2323
}
2424
}

0 commit comments

Comments
 (0)