From 0247081067cb7b35a343551c72b9e0e9ae3342c8 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Thu, 20 Dec 2018 08:43:55 -0500 Subject: [PATCH 1/6] Initial Azure Pipelines support (Linux, Windows, and macOS) --- .azure-pipelines-steps.yml | 44 ++++++++++++++++++++++++++++++++++++++ .azure-pipelines.yml | 38 ++++++++++++++++++++++++++++++++ e2e/Utils.js | 2 +- e2e/runJest.js | 4 ++-- 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 .azure-pipelines-steps.yml create mode 100644 .azure-pipelines.yml diff --git a/.azure-pipelines-steps.yml b/.azure-pipelines-steps.yml new file mode 100644 index 000000000000..a97cb478cb1e --- /dev/null +++ b/.azure-pipelines-steps.yml @@ -0,0 +1,44 @@ +# +# CI build and test steps. See azure-pipelines.yml for job details. +# + +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 repo source files into 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..11596dedbb81 --- /dev/null +++ b/.azure-pipelines.yml @@ -0,0 +1,38 @@ +# +# Azure Pipelines CI configuration for 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 + displayName: 'Clone with LF preserved' + + - script: choco install hg + displayName: 'Install Mercurial' + + - template: .azure-pipelines-steps.yml + +- job: macOS + pool: + vmImage: macos-10.13 + steps: + - script: brew install mercurial + displayName: 'Install Mercurial' + + - template: .azure-pipelines-steps.yml + +variables: + # Ensures output produced by Jest for certain tests includes ANSI escape characters (needed to match snapshots) + FORCE_COLOR: 1 + # Default checkout directory is "s", but inline snapshot tests will fail due to assumption that Jest is running under a "jest" folder + # (see packages/jest-message-util/src/index.js PATH_JEST_PACKAGES) + JEST_DIR: $(Agent.BuildDirectory)/jest \ No newline at end of file diff --git a/e2e/Utils.js b/e2e/Utils.js index c99ae907ce33..47dca4e0360b 100644 --- a/e2e/Utils.js +++ b/e2e/Utils.js @@ -137,7 +137,7 @@ export const createEmptyPackage = ( }; export const extractSummary = (stdout: string) => { - const match = stdout.match( + const match = stdout.replace(/(?:\\[rn])+/g, '\n').match( /Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm, ); if (!match) { 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); From cbd61db6a4acdb1341e3cc68a3a707e77754ea6f Mon Sep 17 00:00:00 2001 From: Kayla Ngan Date: Thu, 27 Dec 2018 10:46:46 -0500 Subject: [PATCH 2/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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 From d378294dd8923a3cf55873da2395266197f980e9 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Mon, 7 Jan 2019 11:28:47 -0500 Subject: [PATCH 3/6] Get tests to pass on Azure Pipelines --- .azure-pipelines.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 11596dedbb81..5b560a96707b 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -5,20 +5,20 @@ jobs: - job: Linux pool: - vmImage: ubuntu-16.04 + vmImage: ubuntu-16.04 steps: - template: .azure-pipelines-steps.yml -- job: Windows +- job: Windows pool: - vmImage: vs2017-win2016 + vmImage: vs2017-win2016 + variables: + VSTS_OVERWRITE_TEMP: true steps: - - script: git config --global core.autocrlf false - displayName: 'Clone with LF preserved' - - - script: choco install hg - displayName: 'Install Mercurial' - + - 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 @@ -26,8 +26,7 @@ jobs: vmImage: macos-10.13 steps: - script: brew install mercurial - displayName: 'Install Mercurial' - + displayName: 'Install Mercurial' - template: .azure-pipelines-steps.yml variables: @@ -35,4 +34,5 @@ variables: FORCE_COLOR: 1 # Default checkout directory is "s", but inline snapshot tests will fail due to assumption that Jest is running under a "jest" folder # (see packages/jest-message-util/src/index.js PATH_JEST_PACKAGES) - JEST_DIR: $(Agent.BuildDirectory)/jest \ No newline at end of file + JEST_DIR: $(Agent.BuildDirectory)/jest + CI: true From c41ae05199f23b659938bb868cbfc77794e2f2d7 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Thu, 10 Jan 2019 08:09:53 -0500 Subject: [PATCH 4/6] Drop unnecessary VSTS_OVERWRITE_TEMP and fix failing tests. See #7598 --- .azure-pipelines.yml | 4 +--- e2e/Utils.js | 8 +++++--- e2e/__tests__/hasteMapSize.test.js | 3 ++- packages/jest-cli/src/SearchSource.js | 1 + packages/jest-config/src/getCacheDirectory.js | 9 +++++++-- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 5b560a96707b..f87035abb706 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -12,8 +12,6 @@ jobs: - job: Windows pool: vmImage: vs2017-win2016 - variables: - VSTS_OVERWRITE_TEMP: true steps: - script: | git config --global core.autocrlf false @@ -25,7 +23,7 @@ jobs: pool: vmImage: macos-10.13 steps: - - script: brew install mercurial + - script: HOMEBREW_NO_AUTO_UPDATE=1 brew install mercurial displayName: 'Install Mercurial' - template: .azure-pipelines-steps.yml diff --git a/e2e/Utils.js b/e2e/Utils.js index 47dca4e0360b..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.replace(/(?:\\[rn])+/g, '\n').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/packages/jest-cli/src/SearchSource.js b/packages/jest-cli/src/SearchSource.js index 1744ef00bb2a..e3420ebe104c 100644 --- a/packages/jest-cli/src/SearchSource.js +++ b/packages/jest-cli/src/SearchSource.js @@ -19,6 +19,7 @@ import testPathPatternToRegExp from './testPathPatternToRegexp'; import {escapePathForRegex} from 'jest-regex-util'; import {replaceRootDirInPath} from 'jest-config'; import {buildSnapshotResolver} from 'jest-snapshot'; +import {sync as realpath} from 'realpath-native'; type SearchResult = {| noSCM?: boolean, diff --git a/packages/jest-config/src/getCacheDirectory.js b/packages/jest-config/src/getCacheDirectory.js index 36bae7092d15..7298a15a5465 100644 --- a/packages/jest-config/src/getCacheDirectory.js +++ b/packages/jest-config/src/getCacheDirectory.js @@ -10,15 +10,20 @@ const path = require('path'); const os = require('os'); +import {sync as realpath} from 'realpath-native'; + const getCacheDirectory = () => { const {getuid} = process; if (getuid == null) { - return path.join(os.tmpdir(), 'jest'); + return path.join(realpath(os.tmpdir()), 'jest'); } // 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)); + return path.join( + realpath(os.tmpdir()), + 'jest_' + getuid.call(process).toString(36), + ); }; export default getCacheDirectory; From abf9347c2d830ddbf436f4a79eef8ff6e00997b5 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 11 Jan 2019 08:21:01 -0500 Subject: [PATCH 5/6] Comment cleanup; fix lint failure in packages/jest-cli/src/SearchSource.js --- .azure-pipelines-steps.yml | 5 +++-- .azure-pipelines.yml | 12 ++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.azure-pipelines-steps.yml b/.azure-pipelines-steps.yml index a97cb478cb1e..5c170b1a2412 100644 --- a/.azure-pipelines-steps.yml +++ b/.azure-pipelines-steps.yml @@ -1,7 +1,8 @@ # -# CI build and test steps. See azure-pipelines.yml for job details. +# Steps for building and testing Jest. See jobs defined in .azure-pipelines.yml # +# Clones the repo steps: - checkout: self @@ -17,7 +18,7 @@ steps: versionSpec: '2.7' displayName: 'Use Python 2.7' -# Workaround to move repo source files into a "jest" folder (see azure-pipelines.yml for details) +# Workaround to move source files under a "jest" folder (see .azure-pipelines.yml for details) - script: | cd / mv $(Build.Repository.LocalPath) $(JEST_DIR) diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index f87035abb706..75a8d7b00508 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -1,5 +1,5 @@ # -# Azure Pipelines CI configuration for Linux, Windows, and macOS. +# Azure Pipelines configuration for building and testing Jest on Linux, Windows, and macOS. # jobs: @@ -23,14 +23,18 @@ jobs: 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: - # Ensures output produced by Jest for certain tests includes ANSI escape characters (needed to match snapshots) + # Used by chalk. Ensures output from Jest includes ANSI escape characters that are needed to match test snapshots. FORCE_COLOR: 1 - # Default checkout directory is "s", but inline snapshot tests will fail due to assumption that Jest is running under a "jest" folder - # (see packages/jest-message-util/src/index.js PATH_JEST_PACKAGES) + + # 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 From dcafcfd36a2819c035c937f4d98764b8ea32456a Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Mon, 14 Jan 2019 15:00:12 -0500 Subject: [PATCH 6/6] Undo change to SearchSource.js due to #7146; address other feedback --- packages/jest-cli/src/SearchSource.js | 1 - packages/jest-config/src/getCacheDirectory.js | 15 +++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/jest-cli/src/SearchSource.js b/packages/jest-cli/src/SearchSource.js index e3420ebe104c..1744ef00bb2a 100644 --- a/packages/jest-cli/src/SearchSource.js +++ b/packages/jest-cli/src/SearchSource.js @@ -19,7 +19,6 @@ import testPathPatternToRegExp from './testPathPatternToRegexp'; import {escapePathForRegex} from 'jest-regex-util'; import {replaceRootDirInPath} from 'jest-config'; import {buildSnapshotResolver} from 'jest-snapshot'; -import {sync as realpath} from 'realpath-native'; type SearchResult = {| noSCM?: boolean, diff --git a/packages/jest-config/src/getCacheDirectory.js b/packages/jest-config/src/getCacheDirectory.js index 7298a15a5465..587d9c21fdb6 100644 --- a/packages/jest-config/src/getCacheDirectory.js +++ b/packages/jest-config/src/getCacheDirectory.js @@ -14,16 +14,15 @@ 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(realpath(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( - realpath(os.tmpdir()), - 'jest_' + getuid.call(process).toString(36), - ); }; export default getCacheDirectory;