diff --git a/.azure-pipelines-steps.yml b/.azure-pipelines-steps.yml new file mode 100644 index 000000000000..5c170b1a2412 --- /dev/null +++ b/.azure-pipelines-steps.yml @@ -0,0 +1,45 @@ +# +# Steps for building and testing Jest. See jobs defined in .azure-pipelines.yml +# + +# Clones the repo +steps: +- checkout: self + +# Ensure Node.js 10 is active +- task: NodeTool@0 + inputs: + versionSpec: '10.x' + displayName: 'Use Node.js 10' + +# Ensure Python 2.7 is active +- task: UsePythonVersion@0 + inputs: + versionSpec: '2.7' + displayName: 'Use Python 2.7' + +# Workaround to move source files under a "jest" folder (see .azure-pipelines.yml for details) +- script: | + cd / + mv $(Build.Repository.LocalPath) $(JEST_DIR) + mkdir $(Build.Repository.LocalPath) + displayName: 'Move source into jest folder' + +# Run yarn to install dependencies and build +- script: yarn + workingDirectory: $(JEST_DIR) + displayName: 'Install dependencies and build' + +# Run test-ci-partial +- script: yarn run test-ci-partial + workingDirectory: $(JEST_DIR) + displayName: 'Run tests' + +# Publish CI test results +- task: PublishTestResults@2 + inputs: + testResultsFiles: '**/reports/junit/*.xml' + searchFolder: $(JEST_DIR) + testRunTitle: 'CI Tests $(Agent.OS)' + displayName: 'Publish test results' + condition: succeededOrFailed() diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml new file mode 100644 index 000000000000..75a8d7b00508 --- /dev/null +++ b/.azure-pipelines.yml @@ -0,0 +1,40 @@ +# +# Azure Pipelines configuration for building and testing Jest on Linux, Windows, and macOS. +# + +jobs: +- job: Linux + pool: + vmImage: ubuntu-16.04 + steps: + - template: .azure-pipelines-steps.yml + +- job: Windows + pool: + vmImage: vs2017-win2016 + steps: + - script: | + git config --global core.autocrlf false + git config --global core.symlinks true + displayName: 'Preserve LF endings and symbolic links on check out' + - template: .azure-pipelines-steps.yml + +- job: macOS + pool: + vmImage: macos-10.13 + steps: + # This step can be removed once Mercurial gets installed on the macOS image. See https://github.com/Microsoft/azure-pipelines-image-generation/issues/604 + - script: HOMEBREW_NO_AUTO_UPDATE=1 brew install mercurial + displayName: 'Install Mercurial' + - template: .azure-pipelines-steps.yml + +variables: + # Used by chalk. Ensures output from Jest includes ANSI escape characters that are needed to match test snapshots. + FORCE_COLOR: 1 + + # By default, Azure Pipelines clones to an "s" directory, which causes tests to fail due to assumption of Jest being run from a "jest" directory. + # See packages/jest-message-util/src/index.js PATH_JEST_PACKAGES for more details. + JEST_DIR: $(Agent.BuildDirectory)/jest + + # Ensures the handful of tests that should be skipped during CI are + CI: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 110188111a8c..75e8894b3e4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -154,6 +154,7 @@ - `[docs]` Add `testPathIgnorePatterns` in CLI documentation ([#7440](https://github.com/facebook/jest/pull/7440)) - `[docs]` Removed misleading text about `describe()` grouping together tests into a test suite ([#7434](https://github.com/facebook/jest/pull/7434)) - `[*]` Replace as many `Object.assign` with object spread as possible +- `[ci]` Initial support for Azure Pipelines ([#7556](https://github.com/facebook/jest/pull/7556)) ### Performance diff --git a/e2e/Utils.js b/e2e/Utils.js index c99ae907ce33..5588bb9d235e 100644 --- a/e2e/Utils.js +++ b/e2e/Utils.js @@ -137,9 +137,11 @@ export const createEmptyPackage = ( }; export const extractSummary = (stdout: string) => { - const match = stdout.match( - /Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm, - ); + const match = stdout + .replace(/(?:\\[rn])+/g, '\n') + .match( + /Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm, + ); if (!match) { throw new Error( ` diff --git a/e2e/__tests__/hasteMapSize.test.js b/e2e/__tests__/hasteMapSize.test.js index 8daf564d28d2..160bf08e0db6 100644 --- a/e2e/__tests__/hasteMapSize.test.js +++ b/e2e/__tests__/hasteMapSize.test.js @@ -13,8 +13,9 @@ import os from 'os'; import path from 'path'; import HasteMap from 'jest-haste-map'; import {cleanup, writeFiles} from '../Utils'; +import {sync as realpath} from 'realpath-native'; -const DIR = path.resolve(os.tmpdir(), 'haste_map_size'); +const DIR = path.resolve(realpath(os.tmpdir()), 'haste_map_size'); beforeEach(() => { cleanup(DIR); diff --git a/e2e/runJest.js b/e2e/runJest.js index 9095e9a54a39..3c49bfc8b383 100644 --- a/e2e/runJest.js +++ b/e2e/runJest.js @@ -31,7 +31,7 @@ export default function runJest( args?: Array, options: RunJestOptions = {}, ) { - const isRelative = dir[0] !== '/'; + const isRelative = !path.isAbsolute(dir); if (isRelative) { dir = path.resolve(__dirname, dir); @@ -101,7 +101,7 @@ export const until = async function( text: string, options: RunJestOptions = {}, ) { - const isRelative = dir[0] !== '/'; + const isRelative = !path.isAbsolute(dir); if (isRelative) { dir = path.resolve(__dirname, dir); diff --git a/packages/jest-config/src/getCacheDirectory.js b/packages/jest-config/src/getCacheDirectory.js index 36bae7092d15..587d9c21fdb6 100644 --- a/packages/jest-config/src/getCacheDirectory.js +++ b/packages/jest-config/src/getCacheDirectory.js @@ -10,15 +10,19 @@ const path = require('path'); const os = require('os'); +import {sync as realpath} from 'realpath-native'; + const getCacheDirectory = () => { const {getuid} = process; + const tmpdir = path.join(realpath(os.tmpdir()), 'jest'); if (getuid == null) { - return path.join(os.tmpdir(), 'jest'); + return tmpdir; + } else { + // On some platforms tmpdir() is `/tmp`, causing conflicts between different + // users and permission issues. Adding an additional subdivision by UID can + // help. + return `${tmpdir}_${getuid.call(process).toString(36)}`; } - // On some platforms tmpdir() is `/tmp`, causing conflicts between different - // users and permission issues. Adding an additional subdivision by UID can - // help. - return path.join(os.tmpdir(), 'jest_' + getuid.call(process).toString(36)); }; export default getCacheDirectory;