diff --git a/.circleci/config.yml b/.circleci/config.yml index 403069d10c218..d6c3494401153 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -150,7 +150,7 @@ commands: default: false trigger_pattern: type: string - default: "packages/*|.circleci/*" + default: "packages/*|.circleci/*|scripts/e2e-test.sh" test_path: type: string test_command: @@ -168,6 +168,9 @@ commands: - run: ./scripts/assert-changed-files.sh "<< parameters.trigger_pattern >>|<< parameters.test_path >>/*" - <<: *attach_to_bootstrap + - run: + name: Install gatsby-dev + command: yarn global add gatsby-dev-cli - run: name: Run tests (using defaults) command: ./scripts/e2e-test.sh "<< parameters.test_path >>" "<< parameters.test_command >>" @@ -179,7 +182,7 @@ jobs: executor: node steps: - checkout - - run: ./scripts/assert-changed-files.sh "packages/*|(e2e|integration)-tests/*|.circleci/*|yarn.lock" + - run: ./scripts/assert-changed-files.sh "packages/*|(e2e|integration)-tests/*|.circleci/*|scripts/e2e-test.sh|yarn.lock" - <<: *restore_cache - <<: *install_node_modules - <<: *check_lockfile @@ -256,7 +259,7 @@ jobs: steps: - e2e-test: test_path: integration-tests/gatsby-cli - trigger_pattern: packages/gatsby-cli/*|packages/gatsby/*|integration-tests/gatsby-cli/* + trigger_pattern: packages/gatsby-cli/*|packages/gatsby/*|integration-tests/gatsby-cli/*|scripts/e2e-test.sh integration_tests_structured_logging: executor: node @@ -369,8 +372,8 @@ jobs: CYPRESS_RECORD_KEY: 3fb49000-4143-4bd8-9ab4-219389060910 steps: - e2e-test: - test_path: e2e-tests/themes/development-runtime - test_command: yarn test + test_path: e2e-tests/themes + test_command: cd development-runtime; yarn test themes_e2e_tests_production_runtime: <<: *e2e-executor @@ -379,8 +382,8 @@ jobs: CYPRESS_RECORD_KEY: e4e7b3b8-e1e7-4a74-a0c9-9ac76585236b steps: - e2e-test: - test_path: e2e-tests/themes/production-runtime - test_command: yarn test + test_path: e2e-tests/themes + test_command: cd production-runtime; yarn test mdx_e2e_tests: <<: *e2e-executor @@ -482,7 +485,7 @@ jobs: steps: - checkout - run: - command: ./scripts/assert-changed-files.sh "packages/*|(e2e|integration)-tests/*|.circleci/*|yarn.lock" + command: ./scripts/assert-changed-files.sh "packages/*|(e2e|integration)-tests/*|.circleci/*|scripts/e2e-test.sh|yarn.lock" shell: bash.exe # Restoring cache takes as long as installing node modules, so skipping # - restore_cache: diff --git a/e2e-tests/contentful/package.json b/e2e-tests/contentful/package.json index 9fb857f48c937..692d092ae4136 100644 --- a/e2e-tests/contentful/package.json +++ b/e2e-tests/contentful/package.json @@ -13,6 +13,7 @@ "gatsby-plugin-sharp": "^3.1.2", "gatsby-source-contentful": "^5.1.1", "gatsby-transformer-remark": "^3.2.0", + "gatsby-transformer-sharp": "^3.3.0", "gatsby-transformer-sqip": "3.1.1", "modern-normalize": "^1.0.0", "prop-types": "^15.7.2", diff --git a/e2e-tests/gatsby-static-image/package.json b/e2e-tests/gatsby-static-image/package.json index 91da06a887b30..8bfbdb634b417 100644 --- a/e2e-tests/gatsby-static-image/package.json +++ b/e2e-tests/gatsby-static-image/package.json @@ -8,6 +8,7 @@ "gatsby": "^2.0.118", "gatsby-plugin-image": "^0.0.2", "gatsby-plugin-sharp": "^2.0.20", + "gatsby-source-filesystem": "^3.3.0", "react": "^16.9.0", "react-dom": "^16.9.0" }, @@ -36,4 +37,4 @@ "type": "git", "url": "https://github.com/gatsbyjs/gatsby-starter-default" } -} \ No newline at end of file +} diff --git a/e2e-tests/production-runtime/package.json b/e2e-tests/production-runtime/package.json index 0b18fb7e55520..5b58d1dc99a5d 100644 --- a/e2e-tests/production-runtime/package.json +++ b/e2e-tests/production-runtime/package.json @@ -7,6 +7,7 @@ "babel-plugin-search-and-replace": "^1.1.0", "cypress": "^6.5.0", "gatsby": "^3.0.0-next.6", + "gatsby-cypress": "^1.3.0", "gatsby-plugin-image": "^1.0.0-next.5", "gatsby-plugin-less": "^5.1.0-next.2", "gatsby-plugin-manifest": "^3.0.0-next.0", @@ -15,6 +16,7 @@ "gatsby-plugin-sass": "^4.1.0-next.2", "gatsby-plugin-sharp": "^3.0.0-next.5", "gatsby-plugin-stylus": "^3.1.0-next.2", + "gatsby-source-filesystem": "^3.3.0", "gatsby-seo": "^0.1.0", "glob": "^7.1.3", "react": "^16.9.0", diff --git a/integration-tests/artifacts/__tests__/index.js b/integration-tests/artifacts/__tests__/index.js index 31ae58b8ff66f..435dd6bd591ad 100644 --- a/integration-tests/artifacts/__tests__/index.js +++ b/integration-tests/artifacts/__tests__/index.js @@ -9,7 +9,7 @@ jest.setTimeout(100000) const publicDir = path.join(process.cwd(), `public`) -const gatsbyBin = path.join(`node_modules`, `.bin`, `gatsby`) +const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`) const manifest = {} const filesToRevert = {} @@ -17,8 +17,8 @@ const filesToRevert = {} function runGatsbyWithRunTestSetup(runNumber = 1) { return function beforeAllImpl() { return new Promise(resolve => { - const gatsbyProcess = spawn(gatsbyBin, [`build`], { - stdio: [`inherit`, `inherit`, `inherit`, `inherit`], + const gatsbyProcess = spawn(process.execPath, [gatsbyBin, `build`], { + stdio: [`inherit`, `inherit`, `inherit`], env: { ...process.env, NODE_ENV: `production`, @@ -331,8 +331,8 @@ function assertNodeCorrectness(runNumber) { beforeAll(done => { fs.removeSync(path.join(__dirname, `__debug__`)) - const gatsbyCleanProcess = spawn(gatsbyBin, [`clean`], { - stdio: [`inherit`, `inherit`, `inherit`, `inherit`], + const gatsbyCleanProcess = spawn(process.execPath, [gatsbyBin, `clean`], { + stdio: [`inherit`, `inherit`, `inherit`], env: { ...process.env, NODE_ENV: `production`, diff --git a/integration-tests/artifacts/package.json b/integration-tests/artifacts/package.json index 2b8b50c1f485c..50b7bf85cabd1 100644 --- a/integration-tests/artifacts/package.json +++ b/integration-tests/artifacts/package.json @@ -10,7 +10,7 @@ "develop": "gatsby develop", "serve": "gatsby serve", "clean": "gatsby clean", - "test": "jest --config=jest.config.js --runInBand" + "test": "jest --runInBand" }, "dependencies": { "gatsby": "^3.0.0-next.0", @@ -19,8 +19,7 @@ }, "devDependencies": { "fs-extra": "^9.0.0", - "jest": "^24.0.0", - "jest-cli": "^24.0.0" + "jest": "^24.0.0" }, "repository": { "type": "git", diff --git a/integration-tests/cache-resilience/__tests__/cache.js b/integration-tests/cache-resilience/__tests__/cache.js index 9271278a34eaa..1bf2a73d6aa01 100644 --- a/integration-tests/cache-resilience/__tests__/cache.js +++ b/integration-tests/cache-resilience/__tests__/cache.js @@ -1,6 +1,7 @@ const fs = require(`fs-extra`) const { spawnSync } = require(`child_process`) const path = require(`path`) +const os = require(`os`) const _ = require(`lodash`) const { ON_PRE_BOOTSTRAP_FILE_PATH, @@ -30,13 +31,7 @@ const getDiskCacheSnapshotSubStateByPlugins = (state, pluginNamesArray) => jest.setTimeout(100000) -const gatsbyBin = path.join( - `node_modules`, - `gatsby`, - `dist`, - `bin`, - `gatsby.js` -) +const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`) const { compareState } = require(`../utils/nodes-diff`) @@ -380,6 +375,10 @@ describe(`Some plugins changed between gatsby runs`, () => { describe(`Query results`, () => { const getQueryResultTestArgs = scenarioName => { + if (os.platform() === "win32") { + scenarioName = scenarioName.replace("/", "\\") + } + const result = { dataFirstRun: states.queryResults.firstRun[scenarioName].data, dataSecondRun: states.queryResults.secondRun[scenarioName].data, diff --git a/integration-tests/cache-resilience/package.json b/integration-tests/cache-resilience/package.json index 5e27ea3122f3a..c23d34d0e830e 100644 --- a/integration-tests/cache-resilience/package.json +++ b/integration-tests/cache-resilience/package.json @@ -7,7 +7,7 @@ "develop": "gatsby develop", "prebuild": "node utils/prebuild.js", "build": "gatsby build", - "test": "jest --verbose", + "test": "jest", "serve": "gatsby serve", "use-setup": "node utils/select-configuration", "inspect-state": "node utils/inspect-state" @@ -22,9 +22,9 @@ "fs-extra": "^9.0.1", "glob": "^7.1.6", "jest": "^24.0.0", - "jest-cli": "^24.0.0", + "jest-serializer-path": "^0.1.15", "lodash": "^4.17.20", "slash": "^3.0.0", "snapshot-diff": "^0.6.1" } -} \ No newline at end of file +} diff --git a/integration-tests/functions/jest-transformer.js b/integration-tests/functions/jest-transformer.js new file mode 100644 index 0000000000000..5c4289ec3330c --- /dev/null +++ b/integration-tests/functions/jest-transformer.js @@ -0,0 +1,4 @@ +const babelPreset = require(`babel-preset-gatsby-package`)() +module.exports = require(`babel-jest`).createTransformer({ + ...babelPreset, +}) diff --git a/integration-tests/functions/jest.config.js b/integration-tests/functions/jest.config.js index 709eb3156898e..8ec23e14f3462 100644 --- a/integration-tests/functions/jest.config.js +++ b/integration-tests/functions/jest.config.js @@ -8,6 +8,6 @@ module.exports = { ], watchPathIgnorePatterns: ["src/api", ".cache"], transform: { - "^.+\\.[jt]sx?$": `../../jest-transformer.js`, + "^.+\\.[jt]sx?$": `./jest-transformer.js`, }, } diff --git a/integration-tests/functions/package.json b/integration-tests/functions/package.json index 5eb694da1f202..df81171e3c2b4 100644 --- a/integration-tests/functions/package.json +++ b/integration-tests/functions/package.json @@ -4,20 +4,23 @@ "private": true, "description": "functions", "author": "Kyle Mathews", - "keywords": ["gatsby"], + "keywords": [ + "gatsby" + ], "scripts": { "build": "gatsby build", "develop": "gatsby develop", "serve": "gatsby serve", - "start-servers-and-test": "start-server-and-test servers '8000|9000' test:jest", + "start-servers-and-test": "start-server-and-test servers \"8000|9000\" test:jest", "servers": "run-p develop serve", "test:jest": "jest", "test": "npm-run-all -s build start-servers-and-test" }, "devDependencies": { + "babel-jest": "^24.0.0", + "babel-preset-gatsby-package": "^1.3.0", "fs-extra": "^9.0.0", "jest": "^24.0.0", - "jest-cli": "^24.0.0", "npm-run-all": "4.1.5", "start-server-and-test": "^1.11.3" }, @@ -27,4 +30,4 @@ "react": "^17.0.1", "react-dom": "^17.0.1" } -} +} \ No newline at end of file diff --git a/integration-tests/gatsby-cli/jest-transformer.js b/integration-tests/gatsby-cli/jest-transformer.js new file mode 100644 index 0000000000000..5c4289ec3330c --- /dev/null +++ b/integration-tests/gatsby-cli/jest-transformer.js @@ -0,0 +1,4 @@ +const babelPreset = require(`babel-preset-gatsby-package`)() +module.exports = require(`babel-jest`).createTransformer({ + ...babelPreset, +}) diff --git a/integration-tests/gatsby-cli/jest.boot.js b/integration-tests/gatsby-cli/jest.boot.js deleted file mode 100644 index 242e23ed3b65c..0000000000000 --- a/integration-tests/gatsby-cli/jest.boot.js +++ /dev/null @@ -1,42 +0,0 @@ -const path = require(`path`) -const execa = require(`execa`) -const fs = require(`fs-extra`) - -module.exports = async () => { - console.log( - `Installing "gatsby-cli" in sandbox directory: "${process.env.GLOBAL_GATSBY_CLI_LOCATION}"` - ) - console.log( - `Tests will use "${process.env.GLOBAL_GATSBY_CLI_LOCATION}/node_modules/.bin/gatsby" CLI to invoke commands` - ) - - await fs.ensureDir(process.env.GLOBAL_GATSBY_CLI_LOCATION) - - await fs.outputJson( - path.join(process.env.GLOBAL_GATSBY_CLI_LOCATION, `package.json`), - { - dependencies: { - "gatsby-cli": "latest", - }, - } - ) - - const gatsbyDevLocation = path.join( - __dirname, - `..`, - `..`, - `packages`, - `gatsby-dev-cli`, - `dist`, - `index.js` - ) - - await execa.node(gatsbyDevLocation, [`--force-install`, `--scan-once`], { - cwd: process.env.GLOBAL_GATSBY_CLI_LOCATION, - stdio: `inherit`, - env: { - // we don't want to run gatsby-dev in with NODE_ENV=test - NODE_ENV: `production`, - }, - }) -} diff --git a/integration-tests/gatsby-cli/jest.config.js b/integration-tests/gatsby-cli/jest.config.js index a561d40a50ecd..1fb16e36ce0b6 100644 --- a/integration-tests/gatsby-cli/jest.config.js +++ b/integration-tests/gatsby-cli/jest.config.js @@ -1,18 +1,6 @@ -const fs = require(`fs`) -const path = require(`path`) -const os = require(`os`) -const baseConfig = require(`../jest.config.js`) - -// install global gatsby-cli to tmp dir to simulate sandbox -const GLOBAL_GATSBY_CLI_LOCATION = (process.env.GLOBAL_GATSBY_CLI_LOCATION = fs.mkdtempSync( - path.join(os.tmpdir(), `gatsby-cli-`) -)) - module.exports = { - ...baseConfig, - globalSetup: "/integration-tests/gatsby-cli/jest.boot.js", - rootDir: `../../`, - globals: { - GLOBAL_GATSBY_CLI_LOCATION, + testPathIgnorePatterns: [`/node_modules/`, `__tests__/fixtures`, `.cache`], + transform: { + "^.+\\.[jt]sx?$": `./jest-transformer.js`, }, } diff --git a/integration-tests/gatsby-cli/package.json b/integration-tests/gatsby-cli/package.json index 8a220609a218f..9abe5f310e7de 100644 --- a/integration-tests/gatsby-cli/package.json +++ b/integration-tests/gatsby-cli/package.json @@ -6,13 +6,20 @@ }, "license": "MIT", "scripts": { - "test": "jest --config=./jest.config.js gatsby-cli/" + "test": "jest" }, "devDependencies": { + "babel-jest": "^24.0.0", + "babel-preset-gatsby-package": "^1.3.0", "del-cli": "^3.0.1", "execa": "^4.0.1", "fs-extra": "^9.0.0", - "jest": "^24.0.0" + "gatsby": "^3.3.0", + "gatsby-cli": "^3.3.0", + "gatsby-core-utils": "^2.3.0", + "jest": "^24.0.0", + "react": "^17.0.2", + "react-dom": "^17.0.2" }, "repository": { "type": "git", diff --git a/integration-tests/gatsby-cli/test-helpers/invoke-cli.js b/integration-tests/gatsby-cli/test-helpers/invoke-cli.js index 56760f64dc313..0ebae05b4f875 100644 --- a/integration-tests/gatsby-cli/test-helpers/invoke-cli.js +++ b/integration-tests/gatsby-cli/test-helpers/invoke-cli.js @@ -4,10 +4,11 @@ import strip from "strip-ansi" import { createLogsMatcher } from "./matcher" const gatsbyBinLocation = join( - GLOBAL_GATSBY_CLI_LOCATION, + __dirname, + "..", `node_modules`, - `.bin`, - `gatsby` + `gatsby-cli`, + `cli.js` ) // Use as `GatsbyCLI.cwd('execution-folder').invoke('new', 'foo')` @@ -17,7 +18,7 @@ export const GatsbyCLI = { invoke(args) { const NODE_ENV = args[0] === `develop` ? `development` : `production` try { - const results = sync(gatsbyBinLocation, [].concat(args), { + const results = sync("node", [gatsbyBinLocation].concat(args), { cwd: join(__dirname, `../`, `./${relativeCwd}`), env: { NODE_ENV, CI: 1, GATSBY_LOGGER: `ink` }, }) @@ -36,7 +37,7 @@ export const GatsbyCLI = { invokeAsync: (args, onExit) => { const NODE_ENV = args[0] === `develop` ? `development` : `production` - const res = execa(gatsbyBinLocation, [].concat(args), { + const res = execa("node", [gatsbyBinLocation].concat(args), { cwd: join(__dirname, `../`, `./${relativeCwd}`), env: { NODE_ENV, CI: 1, GATSBY_LOGGER: `ink` }, }) diff --git a/integration-tests/gatsby-pipeline/__tests__/lazy-image-build/develop.js b/integration-tests/gatsby-pipeline/__tests__/lazy-image-build/develop.js index b4f1abb947868..ada2b2ee4e074 100644 --- a/integration-tests/gatsby-pipeline/__tests__/lazy-image-build/develop.js +++ b/integration-tests/gatsby-pipeline/__tests__/lazy-image-build/develop.js @@ -3,6 +3,7 @@ const path = require(`path`) const fs = require(`fs-extra`) const glob = require(`glob`) const fetch = require(`node-fetch`) +const md5File = require(`md5-file`) const createDevServer = require(`../../utils/create-devserver`) const basePath = path.resolve(__dirname, `../../`) @@ -22,9 +23,12 @@ describe(`Lazy images`, () => { test(`should process images on demand`, async () => { const { kill } = await createDevServer() + const contentDigest = await md5File( + path.resolve("./src/images/gatsby-astronaut.png") + ) const response = await fetch( - `http://localhost:8000/static/6d91c86c0fde632ba4cd01062fd9ccfa/e4795/gatsby-astronaut.png` + `http://localhost:8000/static/${contentDigest}/630fb/gatsby-astronaut.png` ) await kill() diff --git a/integration-tests/gatsby-pipeline/jest.config.js b/integration-tests/gatsby-pipeline/jest.config.js new file mode 100644 index 0000000000000..014b9dac080ad --- /dev/null +++ b/integration-tests/gatsby-pipeline/jest.config.js @@ -0,0 +1,8 @@ +module.exports = { + testPathIgnorePatterns: [ + `/node_modules/`, + `__tests__/fixtures`, + `__testfixtures__`, + `.cache`, + ], +} diff --git a/integration-tests/gatsby-pipeline/package.json b/integration-tests/gatsby-pipeline/package.json index e2d65b6b1c11e..f8acaeecf827a 100644 --- a/integration-tests/gatsby-pipeline/package.json +++ b/integration-tests/gatsby-pipeline/package.json @@ -23,14 +23,15 @@ "scripts": { "build": "gatsby build --prefix-paths", "develop": "gatsby develop", - "test": "jest --config=../jest.config.js gatsby-pipeline/" + "test": "jest" }, "devDependencies": { "execa": "^4.0.3", "fs-extra": "^9.0.1", + "md5-file": "^5.0.0", "node-fetch": "^2.6.0", "jest": "^25.5.4", - "jest-cli": "^25.5.4" + "tree-kill": "^1.2.2" }, "repository": { "type": "git", diff --git a/integration-tests/gatsby-pipeline/utils/create-devserver.js b/integration-tests/gatsby-pipeline/utils/create-devserver.js index 81ae0168b8fe2..3f36dc8249257 100644 --- a/integration-tests/gatsby-pipeline/utils/create-devserver.js +++ b/integration-tests/gatsby-pipeline/utils/create-devserver.js @@ -1,5 +1,6 @@ const execa = require(`execa`) const path = require(`path`) +const kill = require("tree-kill") const basePath = path.resolve(__dirname, `../`) const killProcess = devProcess => @@ -11,9 +12,7 @@ const killProcess = devProcess => }, 0) }) - // If pid is less than -1, then sig is sent to every process in the process group whose ID is -pid. - // @see https://stackoverflow.com/a/33367711 - process.kill(-devProcess.pid) + kill(devProcess.pid) }) module.exports = () => @@ -21,7 +20,6 @@ module.exports = () => const devProcess = execa(`yarn`, [`develop`], { cwd: basePath, env: { NODE_ENV: `development` }, - detached: true, }) devProcess.stdout.on(`data`, chunk => { diff --git a/integration-tests/gatsby-source-wordpress/package.json b/integration-tests/gatsby-source-wordpress/package.json index 9e9749b924f37..122f11287ce40 100644 --- a/integration-tests/gatsby-source-wordpress/package.json +++ b/integration-tests/gatsby-source-wordpress/package.json @@ -4,8 +4,8 @@ "private": true, "description": "A simple Gatsby WP site for running integrations tests", "scripts": { - "run-jest": "jest --config=jest.config.js --runInBand", - "test": "npm run run-jest && WARM_CACHE=true npm run run-jest" + "run-jest": "jest --runInBand", + "test": "npm run run-jest && cross-env WARM_CACHE=true npm run run-jest" }, "author": "Tyler Barnes ", "license": "MIT", @@ -14,9 +14,12 @@ "gatsby-plugin-sharp": "next", "gatsby-source-filesystem": "next", "gatsby-source-wordpress": "next", - "gatsby-transformer-sharp": "next" + "gatsby-transformer-sharp": "next", + "react": "^17.0.2", + "react-dom": "^17.0.2" }, "devDependencies": { + "cross-env": "^7.0.3", "dotenv": "^8.2.0", "jest": "^26.6.3", "rimraf": "^3.0.2", diff --git a/integration-tests/gatsby-source-wordpress/test-fns/test-utils/get-gatsby-process.js b/integration-tests/gatsby-source-wordpress/test-fns/test-utils/get-gatsby-process.js index 49d6e8de8f414..6132543997345 100644 --- a/integration-tests/gatsby-source-wordpress/test-fns/test-utils/get-gatsby-process.js +++ b/integration-tests/gatsby-source-wordpress/test-fns/test-utils/get-gatsby-process.js @@ -2,7 +2,7 @@ const { spawn } = require(`child_process`) const path = require(`path`) const rimraf = require("rimraf") -const gatsbyBin = path.join(`node_modules`, `.bin`, `gatsby`) +const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`) exports.gatsbyCleanBeforeAll = async done => { const gatsbySiteDir = path.join(__dirname, `..`, `..`) @@ -23,10 +23,10 @@ exports.gatsbyCleanBeforeAll = async done => { exports.spawnGatsbyProcess = (command = `develop`, env = {}) => spawn( - gatsbyBin, - [command, ...(command === `develop` ? ["-H", "localhost"] : [])], + process.execPath, + [gatsbyBin, command, ...(command === `develop` ? ["-H", "localhost"] : [])], { - stdio: [`inherit`, `inherit`, `inherit`, `inherit`], + stdio: [`inherit`, `inherit`, `inherit`], env: { ...process.env, NODE_ENV: command === `develop` ? `development` : `production`, diff --git a/integration-tests/images/jest-transformer.js b/integration-tests/images/jest-transformer.js new file mode 100644 index 0000000000000..5c4289ec3330c --- /dev/null +++ b/integration-tests/images/jest-transformer.js @@ -0,0 +1,4 @@ +const babelPreset = require(`babel-preset-gatsby-package`)() +module.exports = require(`babel-jest`).createTransformer({ + ...babelPreset, +}) diff --git a/integration-tests/images/jest.config.js b/integration-tests/images/jest.config.js new file mode 100644 index 0000000000000..1fb16e36ce0b6 --- /dev/null +++ b/integration-tests/images/jest.config.js @@ -0,0 +1,6 @@ +module.exports = { + testPathIgnorePatterns: [`/node_modules/`, `__tests__/fixtures`, `.cache`], + transform: { + "^.+\\.[jt]sx?$": `./jest-transformer.js`, + }, +} diff --git a/integration-tests/images/package.json b/integration-tests/images/package.json index 120c9fa69828e..aaa305f1f42e9 100644 --- a/integration-tests/images/package.json +++ b/integration-tests/images/package.json @@ -6,7 +6,7 @@ "develop": "gatsby develop", "build": "gatsby build", "build-and-test": "yarn build && yarn test", - "test": "jest --config=../jest.config.js images/", + "test": "jest", "serve": "gatsby serve" }, "dependencies": { @@ -19,8 +19,9 @@ "react-dom": "^16.9.0" }, "devDependencies": { + "babel-preset-gatsby-package": "^1.3.0", + "babel-jest": "^24.0.0", "jest": "^24.0.0", - "jest-cli": "^24.0.0", "pixelmatch": "^5.2.1" } -} \ No newline at end of file +} diff --git a/integration-tests/jest.config.js b/integration-tests/jest.config.js deleted file mode 100644 index 77cf00465df54..0000000000000 --- a/integration-tests/jest.config.js +++ /dev/null @@ -1,20 +0,0 @@ -const glob = require(`glob`) - -const pkgs = glob - .sync(`${__dirname}/*/`) - .map(p => p.replace(__dirname, `/integration-tests`)) - -module.exports = { - rootDir: `../`, - roots: pkgs, - testPathIgnorePatterns: [ - `/examples/`, - `/www/`, - `/dist/`, - `/node_modules/`, - `__tests__/fixtures`, - `__testfixtures__`, - `.cache`, - ], - transform: { "^.+\\.[jt]s$": `/jest-transformer.js` }, -} diff --git a/integration-tests/long-term-caching/jest.config.js b/integration-tests/long-term-caching/jest.config.js new file mode 100644 index 0000000000000..4e5a78b25d7bf --- /dev/null +++ b/integration-tests/long-term-caching/jest.config.js @@ -0,0 +1,3 @@ +module.exports = { + testPathIgnorePatterns: [`/node_modules/`, `__tests__/fixtures`, `.cache`], +} diff --git a/integration-tests/long-term-caching/package.json b/integration-tests/long-term-caching/package.json index ac6ce781196e3..cf9e523c4e615 100644 --- a/integration-tests/long-term-caching/package.json +++ b/integration-tests/long-term-caching/package.json @@ -5,7 +5,7 @@ "scripts": { "develop": "gatsby develop", "build": "gatsby build", - "test": "jest --config=../jest.config.js long-term-caching/", + "test": "jest", "serve": "gatsby serve" }, "dependencies": { @@ -16,7 +16,6 @@ }, "devDependencies": { "babel-plugin-dynamic-import-node-sync": "^2.0.1", - "jest": "^24.0.0", - "jest-cli": "^24.0.0" + "jest": "^24.0.0" } -} \ No newline at end of file +} diff --git a/integration-tests/ssr/jest.config.js b/integration-tests/ssr/jest.config.js index 4abafe97fa92b..57d3e1a6afb2b 100644 --- a/integration-tests/ssr/jest.config.js +++ b/integration-tests/ssr/jest.config.js @@ -5,10 +5,4 @@ module.exports = { `.cache`, `src/test`, ], - transform: { - "^.+\\.[jt]sx?$": `../../jest-transformer.js`, - }, - moduleNameMapper: { - "\\.(css)$": `/__mocks__/styleMock.js`, - }, } diff --git a/integration-tests/ssr/package.json b/integration-tests/ssr/package.json index 796d5d8614367..24a7d7323e54b 100644 --- a/integration-tests/ssr/package.json +++ b/integration-tests/ssr/package.json @@ -17,7 +17,6 @@ "cross-env": "^5.0.2", "fs-extra": "^9.0.0", "jest": "^24.0.0", - "jest-cli": "^24.0.0", "jest-diff": "^24.0.0", "npm-run-all": "4.1.5", "start-server-and-test": "^1.11.3" @@ -36,6 +35,6 @@ "start-dev-server": "start-server-and-test develop http://localhost:8000 test:jest", "test": "cross-env GATSBY_EXPERIMENTAL_DEV_SSR=true npm-run-all -s build start-dev-server", "test-output": "node test-output.js", - "test:jest": "jest --config=jest.config.js --runInBand" + "test:jest": "jest --runInBand" } } diff --git a/integration-tests/structured-logging/__tests__/ipc-send.js b/integration-tests/structured-logging/__tests__/ipc-send.js index ad9494843cc73..82940fd6858cb 100644 --- a/integration-tests/structured-logging/__tests__/ipc-send.js +++ b/integration-tests/structured-logging/__tests__/ipc-send.js @@ -3,13 +3,7 @@ const path = require(`path`) jest.setTimeout(20000) // 20s -const gatsbyBin = path.join( - `node_modules`, - `gatsby`, - `dist`, - `bin`, - `gatsby.js` -) +const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`) describe(`IPC Send`, () => { let gatsbyProcess diff --git a/integration-tests/structured-logging/__tests__/logs.js b/integration-tests/structured-logging/__tests__/logs.js index 2a6cfe8b4261d..5d4bc5b1f0bb2 100644 --- a/integration-tests/structured-logging/__tests__/logs.js +++ b/integration-tests/structured-logging/__tests__/logs.js @@ -3,13 +3,7 @@ const path = require(`path`) jest.setTimeout(100000) -const gatsbyBin = path.join( - `node_modules`, - `gatsby`, - `dist`, - `bin`, - `gatsby.js` -) +const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`) describe(`Activities`, () => { let gatsbyProcess diff --git a/integration-tests/structured-logging/__tests__/panic.js b/integration-tests/structured-logging/__tests__/panic.js index 80f3049ec9f2a..2ddff63a22dc0 100644 --- a/integration-tests/structured-logging/__tests__/panic.js +++ b/integration-tests/structured-logging/__tests__/panic.js @@ -3,13 +3,7 @@ const path = require(`path`) jest.setTimeout(100000) -const gatsbyBin = path.join( - `node_modules`, - `gatsby`, - `dist`, - `bin`, - `gatsby.js` -) +const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`) describe(`Panic`, () => { let gatsbyProcess diff --git a/integration-tests/structured-logging/__tests__/plugin-errors.js b/integration-tests/structured-logging/__tests__/plugin-errors.js index 84f4f4b28d767..fc89c86023025 100644 --- a/integration-tests/structured-logging/__tests__/plugin-errors.js +++ b/integration-tests/structured-logging/__tests__/plugin-errors.js @@ -3,13 +3,7 @@ const path = require(`path`) jest.setTimeout(100000) -const gatsbyBin = path.join( - `node_modules`, - `gatsby`, - `dist`, - `bin`, - `gatsby.js` -) +const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`) describe(`Plugin Errors`, () => { let gatsbyProcess @@ -62,10 +56,10 @@ describe(`Plugin Errors`, () => { level: `ERROR`, category: `SYSTEM`, text: `Error text is MORE ERROR!`, - code: `structured-plugin-errors_12345` - }) - }) - }) + code: `structured-plugin-errors_12345`, + }), + }), + }), ]) ) diff --git a/integration-tests/structured-logging/__tests__/status.js b/integration-tests/structured-logging/__tests__/status.js index e4016e4fc3249..6cda1bb47c224 100644 --- a/integration-tests/structured-logging/__tests__/status.js +++ b/integration-tests/structured-logging/__tests__/status.js @@ -4,13 +4,7 @@ const path = require(`path`) jest.setTimeout(100000) -const gatsbyBin = path.join( - `node_modules`, - `gatsby`, - `dist`, - `bin`, - `gatsby.js` -) +const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`) describe(`Successful Build`, () => { let gatsbyProcess diff --git a/integration-tests/structured-logging/__tests__/to-do.js b/integration-tests/structured-logging/__tests__/to-do.js index 103b1d74d8841..495c83a4d1ca0 100644 --- a/integration-tests/structured-logging/__tests__/to-do.js +++ b/integration-tests/structured-logging/__tests__/to-do.js @@ -2,11 +2,12 @@ // Should errors that are not followed panic(onBuild)/process.exit be actually errors // or warnings? If yes, then we should add assertions for SUCCESS status that no errors are // emitted -const { spawn, execSync } = require(`child_process`) +const { spawn } = require(`child_process`) const EventEmitter = require(`events`) const fetch = require(`node-fetch`) const fs = require(`fs-extra`) const path = require(`path`) +const cpy = require(`cpy`) const { first, last } = require(`lodash`) // const { groupBy, filter } = require(`lodash`) const joi = require(`joi`) @@ -17,13 +18,7 @@ const ISO8601 = /^\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z jest.setTimeout(100000) -const gatsbyBin = path.join( - `node_modules`, - `gatsby`, - `dist`, - `bin`, - `gatsby.js` -) +const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`) const defaultStdio = `ignore` @@ -362,6 +357,16 @@ describe(`develop`, () => { }) describe(`code change`, () => { + beforeAll(() => { + return cpy( + path.join(__dirname, "../src/pages/index.js"), + path.join(__dirname, "../original/"), + { + overwrite: true, + } + ) + }) + describe(`invalid`, () => { beforeAll(async done => { clearEvents() @@ -407,8 +412,12 @@ describe(`develop`, () => { beforeAll(async done => { clearEvents() - execSync( - `git checkout -- ${require.resolve(`../src/pages/index.js`)}` + await cpy( + path.join(__dirname, "../original/index.js"), + path.join(__dirname, "../src/pages/"), + { + overwrite: true, + } ) eventEmitter.once(`done`, () => { diff --git a/integration-tests/structured-logging/__tests__/validate-options.js b/integration-tests/structured-logging/__tests__/validate-options.js index 9bcbcc5a02aac..581cf3efcad38 100644 --- a/integration-tests/structured-logging/__tests__/validate-options.js +++ b/integration-tests/structured-logging/__tests__/validate-options.js @@ -3,13 +3,7 @@ const path = require(`path`) jest.setTimeout(100000) -const gatsbyBin = path.join( - `node_modules`, - `gatsby`, - `dist`, - `bin`, - `gatsby.js` -) +const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`) describe(`Validate Plugin Options`, () => { let gatsbyProcess @@ -63,37 +57,35 @@ describe(`Validate Plugin Options`, () => { level: `ERROR`, category: `USER`, context: expect.objectContaining({ - pluginName: expect.stringContaining("integration-tests/structured-logging/local-plugin-with-path/index.js"), + pluginName: expect.stringContaining( + "integration-tests/structured-logging/local-plugin-with-path/index.js" + ), validationErrors: expect.arrayContaining([ { context: { key: "required", - label: "required" + label: "required", }, - message: "\"required\" is required", - path: [ - "required" - ], - type: "any.required" + message: '"required" is required', + path: ["required"], + type: "any.required", }, { context: { key: "optionalString", label: "optionalString", - value: 1234 + value: 1234, }, - message: "\"optionalString\" must be a string", - path: [ - "optionalString" - ], - type: "string.base" - } - ]) + message: '"optionalString" must be a string', + path: ["optionalString"], + type: "string.base", + }, + ]), }), code: `11331`, type: `PLUGIN`, - }) - }) + }), + }), }), // Local plugin with name in gatsby-config expect.objectContaining({ @@ -109,33 +101,29 @@ describe(`Validate Plugin Options`, () => { { context: { key: "required", - label: "required" + label: "required", }, - message: "\"required\" is required", - path: [ - "required" - ], - type: "any.required" + message: '"required" is required', + path: ["required"], + type: "any.required", }, { context: { key: "optionalString", label: "optionalString", - value: 1234 + value: 1234, }, - message: "\"optionalString\" must be a string", - path: [ - "optionalString" - ], - type: "string.base" - } - ]) + message: '"optionalString" must be a string', + path: ["optionalString"], + type: "string.base", + }, + ]), }), code: `11331`, type: `PLUGIN`, - }) - }) - }) + }), + }), + }), ]) ) }) diff --git a/integration-tests/structured-logging/package.json b/integration-tests/structured-logging/package.json index ca651d62c9c17..eabed68782894 100644 --- a/integration-tests/structured-logging/package.json +++ b/integration-tests/structured-logging/package.json @@ -6,7 +6,7 @@ "develop": "gatsby develop", "build": "gatsby build", "test-comment": "We use --runInBand to ensure we don't spawn multiple gatsby processes concurrently", - "test": "jest --config=jest.config.js --runInBand", + "test": "jest --runInBand", "serve": "gatsby serve" }, "dependencies": { @@ -17,11 +17,11 @@ }, "devDependencies": { "babel-plugin-dynamic-import-node-sync": "^2.0.1", + "cpy": "^8.1.2", "fs-extra": "^9.0.1", "jest": "^24.0.0", - "jest-cli": "^24.0.0", "joi": "^17.4.0", "lodash": "^4.17.20", "node-fetch": "^2.6.1" } -} \ No newline at end of file +} diff --git a/jest-transformer.js b/jest-transformer.js index 23df1281c9a06..5c4289ec3330c 100644 --- a/jest-transformer.js +++ b/jest-transformer.js @@ -1,11 +1,4 @@ const babelPreset = require(`babel-preset-gatsby-package`)() module.exports = require(`babel-jest`).createTransformer({ ...babelPreset, - overrides: [ - ...(babelPreset.overrides || []), - { - test: [`**/*.ts`, `**/*.tsx`], - plugins: [[`@babel/plugin-transform-typescript`, { isTSX: true }]], - }, - ], }) diff --git a/scripts/cypress-run-with-conditional-record-flag.js b/scripts/cypress-run-with-conditional-record-flag.js index 697b6550c2baa..559ebd8887ed8 100644 --- a/scripts/cypress-run-with-conditional-record-flag.js +++ b/scripts/cypress-run-with-conditional-record-flag.js @@ -1,9 +1,17 @@ const childProcess = require(`child_process`) const path = require(`path`) -const { isCI } = require(`gatsby-core-utils`) + +const IS_CI = !!( + process.env.CI || // Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari + process.env.CONTINUOUS_INTEGRATION || // Travis CI, Cirrus CI + process.env.BUILD_NUMBER || // Jenkins, TeamCity + process.env.RUN_ID || // TaskCluster, dsari + exports.name || + false +) const shouldRecord = - !!process.env.CYPRESS_PROJECT_ID && !!process.env.CYPRESS_RECORD_KEY && isCI() + !!process.env.CYPRESS_PROJECT_ID && !!process.env.CYPRESS_RECORD_KEY && IS_CI const cypressBin = path.join(process.cwd(), `node_modules/.bin/cypress`) diff --git a/scripts/e2e-test.sh b/scripts/e2e-test.sh index 2068b9134af07..3027910c532cc 100755 --- a/scripts/e2e-test.sh +++ b/scripts/e2e-test.sh @@ -3,20 +3,33 @@ set -e # bail on errors SRC_PATH=$1 CUSTOM_COMMAND="${2:-yarn test}" -GATSBY_PATH="${CIRCLE_WORKING_DIRECTORY:-../../}" +eval GATSBY_PATH=${CIRCLE_WORKING_DIRECTORY:-../..} +TMP_LOCATION=$(mktemp -d); + +mkdir -p $TMP_LOCATION/$SRC_PATH +TMP_TEST_LOCATION=$TMP_LOCATION/$SRC_PATH + +mkdir -p $TMP_LOCATION/scripts/ +mkdir -p $TMP_TEST_LOCATION # cypress docker does not support sudo and does not need it, but the default node executor does -command -v gatsby-dev || command -v sudo && sudo npm install -g gatsby-dev-cli@next || npm install -g gatsby-dev-cli@next +command -v gatsby-dev || (command -v sudo && sudo npm install -g gatsby-dev-cli@next) || npm install -g gatsby-dev-cli@next + +echo "Copy $SRC_PATH into $TMP_LOCATION to isolate test" +cp -Rv $SRC_PATH/. $TMP_TEST_LOCATION +cp -Rv $GATSBY_PATH/scripts/. $TMP_LOCATION/scripts/ # setting up child integration test link to gatsby packages -cd "$SRC_PATH" +cd "$TMP_TEST_LOCATION" + gatsby-dev --set-path-to-repo "$GATSBY_PATH" -gatsby-dev --force-install --scan-once # install _all_ files in gatsby/packages +gatsby-dev --force-install --scan-once # Do not copy files, only install through npm, like our users would if test -f "./node_modules/.bin/gatsby"; then chmod +x ./node_modules/.bin/gatsby # this is sometimes necessary to ensure executable echo "Gatsby bin chmoded" else echo "Gatsby bin doesn't exist. Skipping chmod." fi + sh -c "$CUSTOM_COMMAND" echo "e2e test run succeeded"