Skip to content

Commit 1527e47

Browse files
authored
tests: isolate tests to tmp directory (gatsbyjs#30646)
When doing e2e-tests or integration tests, isolate the projects to tmp so it can't take any modules from the monorepo.
1 parent 643ea7a commit 1527e47

Some content is hidden

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

41 files changed

+203
-252
lines changed

.circleci/config.yml

+11-8
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ commands:
150150
default: false
151151
trigger_pattern:
152152
type: string
153-
default: "packages/*|.circleci/*"
153+
default: "packages/*|.circleci/*|scripts/e2e-test.sh"
154154
test_path:
155155
type: string
156156
test_command:
@@ -168,6 +168,9 @@ commands:
168168
- run: ./scripts/assert-changed-files.sh "<< parameters.trigger_pattern >>|<< parameters.test_path >>/*"
169169

170170
- <<: *attach_to_bootstrap
171+
- run:
172+
name: Install gatsby-dev
173+
command: yarn global add gatsby-dev-cli
171174
- run:
172175
name: Run tests (using defaults)
173176
command: ./scripts/e2e-test.sh "<< parameters.test_path >>" "<< parameters.test_command >>"
@@ -179,7 +182,7 @@ jobs:
179182
executor: node
180183
steps:
181184
- checkout
182-
- run: ./scripts/assert-changed-files.sh "packages/*|(e2e|integration)-tests/*|.circleci/*|yarn.lock"
185+
- run: ./scripts/assert-changed-files.sh "packages/*|(e2e|integration)-tests/*|.circleci/*|scripts/e2e-test.sh|yarn.lock"
183186
- <<: *restore_cache
184187
- <<: *install_node_modules
185188
- <<: *check_lockfile
@@ -264,7 +267,7 @@ jobs:
264267
steps:
265268
- e2e-test:
266269
test_path: integration-tests/gatsby-cli
267-
trigger_pattern: packages/gatsby-cli/*|packages/gatsby/*|integration-tests/gatsby-cli/*
270+
trigger_pattern: packages/gatsby-cli/*|packages/gatsby/*|integration-tests/gatsby-cli/*|scripts/e2e-test.sh
268271

269272
integration_tests_structured_logging:
270273
executor: node
@@ -377,8 +380,8 @@ jobs:
377380
CYPRESS_RECORD_KEY: 3fb49000-4143-4bd8-9ab4-219389060910
378381
steps:
379382
- e2e-test:
380-
test_path: e2e-tests/themes/development-runtime
381-
test_command: yarn test
383+
test_path: e2e-tests/themes
384+
test_command: cd development-runtime; yarn test
382385

383386
themes_e2e_tests_production_runtime:
384387
<<: *e2e-executor
@@ -387,8 +390,8 @@ jobs:
387390
CYPRESS_RECORD_KEY: e4e7b3b8-e1e7-4a74-a0c9-9ac76585236b
388391
steps:
389392
- e2e-test:
390-
test_path: e2e-tests/themes/production-runtime
391-
test_command: yarn test
393+
test_path: e2e-tests/themes
394+
test_command: cd production-runtime; yarn test
392395

393396
mdx_e2e_tests:
394397
<<: *e2e-executor
@@ -490,7 +493,7 @@ jobs:
490493
steps:
491494
- checkout
492495
- run:
493-
command: ./scripts/assert-changed-files.sh "packages/*|(e2e|integration)-tests/*|.circleci/*|yarn.lock"
496+
command: ./scripts/assert-changed-files.sh "packages/*|(e2e|integration)-tests/*|.circleci/*|scripts/e2e-test.sh|yarn.lock"
494497
shell: bash.exe
495498
# Restoring cache takes as long as installing node modules, so skipping
496499
# - restore_cache:

e2e-tests/contentful/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"gatsby-plugin-sharp": "^3.1.2",
1414
"gatsby-source-contentful": "^5.1.1",
1515
"gatsby-transformer-remark": "^3.2.0",
16+
"gatsby-transformer-sharp": "^3.3.0",
1617
"gatsby-transformer-sqip": "3.1.1",
1718
"modern-normalize": "^1.0.0",
1819
"prop-types": "^15.7.2",

e2e-tests/gatsby-static-image/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"gatsby": "^2.0.118",
99
"gatsby-plugin-image": "^0.0.2",
1010
"gatsby-plugin-sharp": "^2.0.20",
11+
"gatsby-source-filesystem": "^3.3.0",
1112
"react": "^16.9.0",
1213
"react-dom": "^16.9.0"
1314
},
@@ -36,4 +37,4 @@
3637
"type": "git",
3738
"url": "https://github.com/gatsbyjs/gatsby-starter-default"
3839
}
39-
}
40+
}

e2e-tests/production-runtime/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"babel-plugin-search-and-replace": "^1.1.0",
88
"cypress": "^6.5.0",
99
"gatsby": "^3.0.0-next.6",
10+
"gatsby-cypress": "^1.3.0",
1011
"gatsby-plugin-image": "^1.0.0-next.5",
1112
"gatsby-plugin-less": "^5.1.0-next.2",
1213
"gatsby-plugin-manifest": "^3.0.0-next.0",
@@ -15,6 +16,7 @@
1516
"gatsby-plugin-sass": "^4.1.0-next.2",
1617
"gatsby-plugin-sharp": "^3.0.0-next.5",
1718
"gatsby-plugin-stylus": "^3.1.0-next.2",
19+
"gatsby-source-filesystem": "^3.3.0",
1820
"gatsby-seo": "^0.1.0",
1921
"glob": "^7.1.3",
2022
"react": "^16.9.0",

integration-tests/artifacts/__tests__/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jest.setTimeout(100000)
99

1010
const publicDir = path.join(process.cwd(), `public`)
1111

12-
const gatsbyBin = path.join(`node_modules`, `.bin`, `gatsby`)
12+
const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`)
1313

1414
const manifest = {}
1515
const filesToRevert = {}
@@ -20,8 +20,8 @@ function runGatsbyWithRunTestSetup(runNumber = 1) {
2020
return function beforeAllImpl() {
2121
exitCode = `reset`
2222
return new Promise(resolve => {
23-
const gatsbyProcess = spawn(gatsbyBin, [`build`], {
24-
stdio: [`inherit`, `inherit`, `inherit`, `inherit`],
23+
const gatsbyProcess = spawn(process.execPath, [gatsbyBin, `build`], {
24+
stdio: [`inherit`, `inherit`, `inherit`],
2525
env: {
2626
...process.env,
2727
NODE_ENV: `production`,
@@ -358,8 +358,8 @@ function assertExitCode(runNumber) {
358358
beforeAll(done => {
359359
fs.removeSync(path.join(__dirname, `__debug__`))
360360

361-
const gatsbyCleanProcess = spawn(gatsbyBin, [`clean`], {
362-
stdio: [`inherit`, `inherit`, `inherit`, `inherit`],
361+
const gatsbyCleanProcess = spawn(process.execPath, [gatsbyBin, `clean`], {
362+
stdio: [`inherit`, `inherit`, `inherit`],
363363
env: {
364364
...process.env,
365365
NODE_ENV: `production`,

integration-tests/artifacts/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"develop": "gatsby develop",
1111
"serve": "gatsby serve",
1212
"clean": "gatsby clean",
13-
"test": "jest --config=jest.config.js --runInBand"
13+
"test": "jest --runInBand"
1414
},
1515
"dependencies": {
1616
"gatsby": "^3.0.0-next.0",
@@ -19,8 +19,7 @@
1919
},
2020
"devDependencies": {
2121
"fs-extra": "^9.0.0",
22-
"jest": "^24.0.0",
23-
"jest-cli": "^24.0.0"
22+
"jest": "^24.0.0"
2423
},
2524
"repository": {
2625
"type": "git",

integration-tests/cache-resilience/__tests__/cache.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require(`fs-extra`)
22
const { spawnSync } = require(`child_process`)
33
const path = require(`path`)
4+
const os = require(`os`)
45
const _ = require(`lodash`)
56
const {
67
ON_PRE_BOOTSTRAP_FILE_PATH,
@@ -30,13 +31,7 @@ const getDiskCacheSnapshotSubStateByPlugins = (state, pluginNamesArray) =>
3031

3132
jest.setTimeout(100000)
3233

33-
const gatsbyBin = path.join(
34-
`node_modules`,
35-
`gatsby`,
36-
`dist`,
37-
`bin`,
38-
`gatsby.js`
39-
)
34+
const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`)
4035

4136
const { compareState } = require(`../utils/nodes-diff`)
4237

@@ -380,6 +375,10 @@ describe(`Some plugins changed between gatsby runs`, () => {
380375

381376
describe(`Query results`, () => {
382377
const getQueryResultTestArgs = scenarioName => {
378+
if (os.platform() === "win32") {
379+
scenarioName = scenarioName.replace("/", "\\")
380+
}
381+
383382
const result = {
384383
dataFirstRun: states.queryResults.firstRun[scenarioName].data,
385384
dataSecondRun: states.queryResults.secondRun[scenarioName].data,

integration-tests/cache-resilience/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"develop": "gatsby develop",
88
"prebuild": "node utils/prebuild.js",
99
"build": "gatsby build",
10-
"test": "jest --verbose",
10+
"test": "jest",
1111
"serve": "gatsby serve",
1212
"use-setup": "node utils/select-configuration",
1313
"inspect-state": "node utils/inspect-state"
@@ -22,9 +22,9 @@
2222
"fs-extra": "^9.0.1",
2323
"glob": "^7.1.6",
2424
"jest": "^24.0.0",
25-
"jest-cli": "^24.0.0",
25+
"jest-serializer-path": "^0.1.15",
2626
"lodash": "^4.17.20",
2727
"slash": "^3.0.0",
2828
"snapshot-diff": "^0.6.1"
2929
}
30-
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const babelPreset = require(`babel-preset-gatsby-package`)()
2+
module.exports = require(`babel-jest`).createTransformer({
3+
...babelPreset,
4+
})

integration-tests/functions/jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ module.exports = {
88
],
99
watchPathIgnorePatterns: ["src/api", ".cache"],
1010
transform: {
11-
"^.+\\.[jt]sx?$": `<rootDir>../../jest-transformer.js`,
11+
"^.+\\.[jt]sx?$": `./jest-transformer.js`,
1212
},
1313
}

integration-tests/functions/package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44
"private": true,
55
"description": "functions",
66
"author": "Kyle Mathews",
7-
"keywords": ["gatsby"],
7+
"keywords": [
8+
"gatsby"
9+
],
810
"scripts": {
911
"build": "gatsby build",
1012
"develop": "gatsby develop",
1113
"serve": "gatsby serve",
12-
"start-servers-and-test": "start-server-and-test servers '8000|9000' test:jest",
14+
"start-servers-and-test": "start-server-and-test servers \"8000|9000\" test:jest",
1315
"servers": "run-p develop serve",
1416
"test:jest": "jest",
1517
"test": "npm-run-all -s build start-servers-and-test"
1618
},
1719
"devDependencies": {
20+
"babel-jest": "^24.0.0",
21+
"babel-preset-gatsby-package": "^1.3.0",
1822
"fs-extra": "^9.0.0",
1923
"jest": "^24.0.0",
20-
"jest-cli": "^24.0.0",
2124
"npm-run-all": "4.1.5",
2225
"start-server-and-test": "^1.11.3"
2326
},
@@ -27,4 +30,4 @@
2730
"react": "^17.0.1",
2831
"react-dom": "^17.0.1"
2932
}
30-
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const babelPreset = require(`babel-preset-gatsby-package`)()
2+
module.exports = require(`babel-jest`).createTransformer({
3+
...babelPreset,
4+
})

integration-tests/gatsby-cli/jest.boot.js

-42
This file was deleted.
+3-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
const fs = require(`fs`)
2-
const path = require(`path`)
3-
const os = require(`os`)
4-
const baseConfig = require(`../jest.config.js`)
5-
6-
// install global gatsby-cli to tmp dir to simulate sandbox
7-
const GLOBAL_GATSBY_CLI_LOCATION = (process.env.GLOBAL_GATSBY_CLI_LOCATION = fs.mkdtempSync(
8-
path.join(os.tmpdir(), `gatsby-cli-`)
9-
))
10-
111
module.exports = {
12-
...baseConfig,
13-
globalSetup: "<rootDir>/integration-tests/gatsby-cli/jest.boot.js",
14-
rootDir: `../../`,
15-
globals: {
16-
GLOBAL_GATSBY_CLI_LOCATION,
2+
testPathIgnorePatterns: [`/node_modules/`, `__tests__/fixtures`, `.cache`],
3+
transform: {
4+
"^.+\\.[jt]sx?$": `./jest-transformer.js`,
175
},
186
}

integration-tests/gatsby-cli/package.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
},
77
"license": "MIT",
88
"scripts": {
9-
"test": "jest --config=./jest.config.js gatsby-cli/"
9+
"test": "jest"
1010
},
1111
"devDependencies": {
12+
"babel-jest": "^24.0.0",
13+
"babel-preset-gatsby-package": "^1.3.0",
1214
"del-cli": "^3.0.1",
1315
"execa": "^4.0.1",
1416
"fs-extra": "^9.0.0",
15-
"jest": "^24.0.0"
17+
"gatsby": "^3.3.0",
18+
"gatsby-cli": "^3.3.0",
19+
"gatsby-core-utils": "^2.3.0",
20+
"jest": "^24.0.0",
21+
"react": "^17.0.2",
22+
"react-dom": "^17.0.2"
1623
},
1724
"repository": {
1825
"type": "git",

integration-tests/gatsby-cli/test-helpers/invoke-cli.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import strip from "strip-ansi"
44
import { createLogsMatcher } from "./matcher"
55

66
const gatsbyBinLocation = join(
7-
GLOBAL_GATSBY_CLI_LOCATION,
7+
__dirname,
8+
"..",
89
`node_modules`,
9-
`.bin`,
10-
`gatsby`
10+
`gatsby-cli`,
11+
`cli.js`
1112
)
1213

1314
// Use as `GatsbyCLI.cwd('execution-folder').invoke('new', 'foo')`
@@ -17,7 +18,7 @@ export const GatsbyCLI = {
1718
invoke(args) {
1819
const NODE_ENV = args[0] === `develop` ? `development` : `production`
1920
try {
20-
const results = sync(gatsbyBinLocation, [].concat(args), {
21+
const results = sync("node", [gatsbyBinLocation].concat(args), {
2122
cwd: join(__dirname, `../`, `./${relativeCwd}`),
2223
env: { NODE_ENV, CI: 1, GATSBY_LOGGER: `ink` },
2324
})
@@ -36,7 +37,7 @@ export const GatsbyCLI = {
3637

3738
invokeAsync: (args, onExit) => {
3839
const NODE_ENV = args[0] === `develop` ? `development` : `production`
39-
const res = execa(gatsbyBinLocation, [].concat(args), {
40+
const res = execa("node", [gatsbyBinLocation].concat(args), {
4041
cwd: join(__dirname, `../`, `./${relativeCwd}`),
4142
env: { NODE_ENV, CI: 1, GATSBY_LOGGER: `ink` },
4243
})

0 commit comments

Comments
 (0)