Skip to content

Commit

Permalink
Chore: CI with Azure Pipelines
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
mysticatea committed Jun 16, 2019
1 parent aef8ea1 commit 41d911a
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 133 deletions.
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

9 changes: 1 addition & 8 deletions 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)
Expand Down Expand Up @@ -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
28 changes: 0 additions & 28 deletions appveyor.yml

This file was deleted.

53 changes: 53 additions & 0 deletions 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
89 changes: 89 additions & 0 deletions tests/lib/_utils.js
Expand Up @@ -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
Expand All @@ -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
};
57 changes: 2 additions & 55 deletions tests/lib/cli-engine/_utils.js
Expand Up @@ -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");
Expand Down Expand Up @@ -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.
Expand All @@ -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) };

/*
Expand All @@ -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.
Expand Down
27 changes: 3 additions & 24 deletions tests/lib/init/npm-utils.js
Expand Up @@ -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();

Expand All @@ -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 });
}

Expand Down

0 comments on commit 41d911a

Please sign in to comment.