From 41d911ad8e2152b089b955cb50087f2bbe137b6a Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sun, 16 Jun 2019 20:54:58 +0900 Subject: [PATCH] Chore: CI with Azure Pipelines [skip ci] --- .travis.yml | 18 ------- README.md | 9 +--- appveyor.yml | 28 ----------- azure-pipelines.yml | 53 ++++++++++++++++++++ tests/lib/_utils.js | 89 ++++++++++++++++++++++++++++++++++ tests/lib/cli-engine/_utils.js | 57 +--------------------- tests/lib/init/npm-utils.js | 27 ++--------- 7 files changed, 148 insertions(+), 133 deletions(-) delete mode 100644 .travis.yml delete mode 100644 appveyor.yml create mode 100644 azure-pipelines.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 40aa2a8a47de..000000000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: node_js -node_js: - - "8" - - "10" - - "11" - - "12" -branches: - only: - - master - -# Run npm test always -script: - - "npm test" -after_success: - - 'if [ "$node_js" = "8" ]; then npm run coveralls; fi' -addons: - code_climate: - repo_token: 1945f7420d920a59f1ff8bf8d1a7b60ccd9e2838a692f73a5a74accd8df30146 diff --git a/README.md b/README.md index 6e5f3db76a65..efc9d7a48d9f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ [![NPM version][npm-image]][npm-url] -[![build status][travis-image]][travis-url] -[![Build status][appveyor-image]][appveyor-url] +[![Build Status](https://dev.azure.com/eslint/eslint/_apis/build/status/eslint.eslint?branchName=master)](https://dev.azure.com/eslint/eslint/_build/latest?definitionId=1&branchName=master) [![Downloads][downloads-image]][downloads-url] [![Bountysource](https://www.bountysource.com/badge/tracker?tracker_id=282608)](https://www.bountysource.com/trackers/282608-eslint?utm_source=282608&utm_medium=shield&utm_campaign=TRACKER_BADGE) [![Join the chat at https://gitter.im/eslint/eslint](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/eslint/eslint?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) @@ -271,11 +270,5 @@ The following companies, organizations, and individuals support ESLint's ongoing [npm-image]: https://img.shields.io/npm/v/eslint.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/eslint -[travis-image]: https://img.shields.io/travis/eslint/eslint/master.svg?style=flat-square -[travis-url]: https://travis-ci.org/eslint/eslint -[appveyor-image]: https://ci.appveyor.com/api/projects/status/iwxmiobcvbw3b0av/branch/master?svg=true -[appveyor-url]: https://ci.appveyor.com/project/nzakas/eslint/branch/master -[coveralls-image]: https://img.shields.io/coveralls/eslint/eslint/master.svg?style=flat-square -[coveralls-url]: https://coveralls.io/r/eslint/eslint?branch=master [downloads-image]: https://img.shields.io/npm/dm/eslint.svg?style=flat-square [downloads-url]: https://www.npmjs.com/package/eslint diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 966263e293f2..000000000000 --- a/appveyor.yml +++ /dev/null @@ -1,28 +0,0 @@ -# AppVeyor file -# http://www.appveyor.com/docs/appveyor-yml - -# Build version format -version: "{build}" - -# What combinations to test -environment: - matrix: - - nodejs_version: 8 - -branches: - only: - - master - -install: - # Get the latest stable version of Node.js - - ps: Install-Product node $env:nodejs_version - # install modules - - npm install - -build: off - -test_script: - - npm test - -matrix: - fast_finish: true # set this flag to immediately finish build once one of the jobs fails. diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000000..1f32418f7216 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,53 @@ +trigger: + - master + +jobs: + - job: tests_on_linux + displayName: Test on Linux + pool: + vmImage: 'Ubuntu-16.04' + strategy: + matrix: + "Node.js 12": + node_version: 12.x + "Node.js 10": + node_version: 10.x + "Node.js 8": + node_version: 8.x + steps: + - task: NodeTool@0 + displayName: Install Node.js + inputs: + versionSpec: $(node_version) + - script: npm install + displayName: Install Packages + - script: npm test + displayName: Test + + - job: tests_on_windows + displayName: Test on Windows + pool: + vmImage: 'Windows-2019' + steps: + - task: NodeTool@0 + displayName: Install Node.js + inputs: + versionSpec: 12.x + - script: npm install + displayName: Install Packages + - script: npm test + displayName: Test + + - job: tests_on_macos + displayName: Test on macOS + pool: + vmImage: 'macOS-10.14' + steps: + - task: NodeTool@0 + displayName: Install Node.js + inputs: + versionSpec: 12.x + - script: npm install + displayName: Install Packages + - script: npm test + displayName: Test diff --git a/tests/lib/_utils.js b/tests/lib/_utils.js index d8b14b6a97cf..3251a6023605 100644 --- a/tests/lib/_utils.js +++ b/tests/lib/_utils.js @@ -5,6 +5,9 @@ "use strict"; +const path = require("path"); +const MemoryFs = require("metro-memory-fs"); + /** * Prevents leading spaces in a multiline template literal from appearing in the resulting string * @param {string[]} strings The strings in the template literal @@ -22,7 +25,93 @@ function unIndent(strings, ...values) { return lines.map(line => line.slice(minLineIndent)).join("\n"); } +// eslint-disable-next-line valid-jsdoc +/** + * Add support of `recursive` option. + * @param {import("fs")} fs The in-memory file system. + * @param {() => string} cwd The current working directory. + * @returns {void} + */ +function supportMkdirRecursiveOption(fs, cwd) { + const { mkdirSync } = fs; + + fs.mkdirSync = (filePath, options) => { + if (typeof options === "object" && options !== null) { + if (options.recursive) { + const absolutePath = path.resolve(cwd(), filePath); + const parentPath = path.dirname(absolutePath); + + if ( + parentPath && + parentPath !== absolutePath && + !fs.existsSync(parentPath) + ) { + fs.mkdirSync(parentPath, options); + } + } + mkdirSync(filePath, options.mode); + } else { + mkdirSync(filePath, options); + } + }; +} + +// eslint-disable-next-line valid-jsdoc +/** + * Define in-memory file system. + * @param {Object} options The options. + * @param {() => string} [options.cwd] The current working directory. + * @param {Object} [options.files] The initial files definition in the in-memory file system. + * @returns {import("fs")} The stubbed `ConfigArrayFactory` class. + */ +function defineInMemoryFs({ + cwd = process.cwd, + files = {} +} = {}) { + + /** + * The in-memory file system for this mock. + * @type {import("fs")} + */ + const fs = new MemoryFs({ + cwd, + platform: process.platform === "win32" ? "win32" : "posix" + }); + + // Support D: drive. + if (process.platform === "win32") { + fs._roots.set("D:", fs._makeDir(0o777)); // eslint-disable-line no-underscore-dangle + } + + supportMkdirRecursiveOption(fs, cwd); + fs.mkdirSync(cwd(), { recursive: true }); + + /* + * Write all files to the in-memory file system and compile all JavaScript + * files then set to `stubs`. + */ + (function initFiles(directoryPath, definition) { + for (const [filename, content] of Object.entries(definition)) { + const filePath = path.resolve(directoryPath, filename); + const parentPath = path.dirname(filePath); + + if (typeof content === "object") { + initFiles(filePath, content); + } else if (typeof content === "string") { + if (!fs.existsSync(parentPath)) { + fs.mkdirSync(parentPath, { recursive: true }); + } + fs.writeFileSync(filePath, content); + } else { + throw new Error(`Invalid content: ${typeof content}`); + } + } + }(cwd(), files)); + + return fs; +} module.exports = { + defineInMemoryFs, unIndent }; diff --git a/tests/lib/cli-engine/_utils.js b/tests/lib/cli-engine/_utils.js index 94d6c0158d2c..54a49b595b45 100644 --- a/tests/lib/cli-engine/_utils.js +++ b/tests/lib/cli-engine/_utils.js @@ -58,8 +58,8 @@ const path = require("path"); const vm = require("vm"); -const MemoryFs = require("metro-memory-fs"); const Proxyquire = require("proxyquire/lib/proxyquire"); +const { defineInMemoryFs } = require("../_utils"); const CascadingConfigArrayFactoryPath = require.resolve("../../../lib/cli-engine/cascading-config-array-factory"); @@ -242,36 +242,6 @@ function fsImportFresh(fs, stubs, absolutePath) { ); } -/** - * Add support of `recursive` option. - * @param {import("fs")} fs The in-memory file system. - * @param {() => string} cwd The current working directory. - * @returns {void} - */ -function supportMkdirRecursiveOption(fs, cwd) { - const { mkdirSync } = fs; - - fs.mkdirSync = (filePath, options) => { - if (typeof options === "object" && options !== null) { - if (options.recursive) { - const absolutePath = path.resolve(cwd(), filePath); - const parentPath = path.dirname(absolutePath); - - if ( - parentPath && - parentPath !== absolutePath && - !fs.existsSync(parentPath) - ) { - fs.mkdirSync(parentPath, options); - } - } - mkdirSync(filePath, options.mode); - } else { - mkdirSync(filePath, options); - } - }; -} - /** * Define stubbed `ConfigArrayFactory` class what uses the in-memory file system. * @param {Object} options The options. @@ -283,19 +253,7 @@ function defineConfigArrayFactoryWithInMemoryFileSystem({ cwd = process.cwd, files = {} } = {}) { - - /** - * The in-memory file system for this mock. - * @type {import("fs")} - */ - const fs = new MemoryFs({ - cwd, - platform: process.platform === "win32" ? "win32" : "posix" - }); - - supportMkdirRecursiveOption(fs, cwd); - fs.mkdirSync(cwd(), { recursive: true }); - + const fs = defineInMemoryFs({ cwd, files }); const RelativeModuleResolver = { resolve: fsResolve.bind(null, fs) }; /* @@ -315,23 +273,12 @@ function defineConfigArrayFactoryWithInMemoryFileSystem({ (function initFiles(directoryPath, definition) { for (const [filename, content] of Object.entries(definition)) { const filePath = path.resolve(directoryPath, filename); - const parentPath = path.dirname(filePath); if (typeof content === "object") { initFiles(filePath, content); continue; } - /* - * Write this file to the in-memory file system. - * For config files that `fs.readFileSync()` or `importFresh()` will - * import. - */ - if (!fs.existsSync(parentPath)) { - fs.mkdirSync(parentPath, { recursive: true }); - } - fs.writeFileSync(filePath, content); - /* * Compile then stub if this file is a JavaScript file. * For parsers and plugins that `require()` will import. diff --git a/tests/lib/init/npm-utils.js b/tests/lib/init/npm-utils.js index ae14f0383490..ed8dbfe6bbb1 100644 --- a/tests/lib/init/npm-utils.js +++ b/tests/lib/init/npm-utils.js @@ -9,13 +9,12 @@ //------------------------------------------------------------------------------ const - path = require("path"), assert = require("chai").assert, spawn = require("cross-spawn"), - MemoryFs = require("metro-memory-fs"), sinon = require("sinon"), npmUtils = require("../../../lib/init/npm-utils"), - log = require("../../../lib/shared/logging"); + log = require("../../../lib/shared/logging"), + { defineInMemoryFs } = require("../_utils"); const proxyquire = require("proxyquire").noCallThru().noPreserveCache(); @@ -29,28 +28,8 @@ const proxyquire = require("proxyquire").noCallThru().noPreserveCache(); * @returns {Object} `npm-utils`. */ function requireNpmUtilsWithInMemoryFileSystem(files) { - const fs = new MemoryFs({ - cwd: process.cwd, - platform: process.platform === "win32" ? "win32" : "posix" - }); - - // Make cwd. - (function mkdir(dirPath) { - const parentPath = path.dirname(dirPath); - - if (parentPath && parentPath !== dirPath && !fs.existsSync(parentPath)) { - mkdir(parentPath); - } - fs.mkdirSync(dirPath); - - }(process.cwd())); - - // Write files. - for (const [filename, content] of Object.entries(files)) { - fs.writeFileSync(filename, content); - } + const fs = defineInMemoryFs({ files }); - // Stub. return proxyquire("../../../lib/init/npm-utils", { fs }); }