Skip to content

Commit

Permalink
Build: CI with Azure Pipelines (#11845)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jun 18, 2019
1 parent 1db3462 commit 4d75956
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 140 deletions.
37 changes: 37 additions & 0 deletions .azure-pipelines/job.yml
@@ -0,0 +1,37 @@
parameters:
name: ""
displayName: ""
vmImage: ""
nodeVersion: ""

jobs:
- job: ${{parameters.name}}
displayName: ${{parameters.displayName}}
pool:
vmImage: ${{parameters.vmImage}}
steps:
- task: NodeTool@0
displayName: Install Node.js
inputs:
versionSpec: ${{parameters.nodeVersion}}

- script: npm install
displayName: Install Packages

- script: npm test
displayName: Test

- task: PublishTestResults@2
displayName: Process Test Results
condition: succeededOrFailed()
inputs:
testRunner: JUnit
testResultsFiles: $(System.DefaultWorkingDirectory)/test-results.xml

- task: PublishCodeCoverageResults@1
displayName: Process Coverage Results
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml
reportDirectory: $(System.DefaultWorkingDirectory)/coverage
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,3 +17,4 @@ versions.json
.sublimelinterrc
.eslint-release-info.json
.nyc_output
/test-results.xml
3 changes: 2 additions & 1 deletion .nycrc
Expand Up @@ -6,7 +6,8 @@
],
"reporter": [
"lcov",
"text-summary"
"text-summary",
"cobertura"
],
"sourceMap": true
}
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

5 changes: 4 additions & 1 deletion Makefile.js
Expand Up @@ -544,7 +544,10 @@ target.test = function() {

echo("Running unit tests");

lastReturn = exec(`${getBinFile("nyc")} -- ${MOCHA} -R progress -t ${MOCHA_TIMEOUT} -c ${TEST_FILES}`);
// In CI (Azure Pipelines), use JUnit reporter.
const reporter = process.env.TF_BUILD ? "mocha-junit-reporter" : "progress";

lastReturn = exec(`${getBinFile("nyc")} -- ${MOCHA} -R ${reporter} -t ${MOCHA_TIMEOUT} -c ${TEST_FILES}`);
if (lastReturn.code !== 0) {
errors++;
}
Expand Down
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.

38 changes: 38 additions & 0 deletions azure-pipelines.yml
@@ -0,0 +1,38 @@
trigger:
- master

jobs:
- template: .azure-pipelines/job.yml
parameters:
name: test_on_linux_node12
displayName: Test on Node.js 12 (Linux)
vmImage: Ubuntu-16.04
nodeVersion: 12.x

- template: .azure-pipelines/job.yml
parameters:
name: test_on_linux_node10
displayName: Test on Node.js 10 (Linux)
vmImage: Ubuntu-16.04
nodeVersion: 10.x

- template: .azure-pipelines/job.yml
parameters:
name: test_on_linux_node8
displayName: Test on Node.js 8 (Linux)
vmImage: Ubuntu-16.04
nodeVersion: 8.x

- template: .azure-pipelines/job.yml
parameters:
name: test_on_windows_node12
displayName: Test on Node.js 12 (Windows)
vmImage: Windows-2019
nodeVersion: 12.x

- template: .azure-pipelines/job.yml
parameters:
name: test_on_macos_node12
displayName: Test on Node.js 12 (macOS)
vmImage: macOS-10.14
nodeVersion: 12.x
16 changes: 14 additions & 2 deletions lib/rule-tester/rule-tester.js
Expand Up @@ -123,6 +123,18 @@ function freezeDeeply(x) {
}
}

/**
* Replace control characters by `\u00xx` form.
* @param {string} text The text to sanitize.
* @returns {string} The sanitized text.
*/
function sanitize(text) {
return text.replace(
/[\u0000-\u001f]/gu, // eslint-disable-line no-control-regex
c => `\\u${c.codePointAt(0).toString(16).padStart(4, "0")}`
);
}

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -613,15 +625,15 @@ class RuleTester {
RuleTester.describe(ruleName, () => {
RuleTester.describe("valid", () => {
test.valid.forEach(valid => {
RuleTester.it(typeof valid === "object" ? valid.code : valid, () => {
RuleTester.it(sanitize(typeof valid === "object" ? valid.code : valid), () => {
testValidTemplate(valid);
});
});
});

RuleTester.describe("invalid", () => {
test.invalid.forEach(invalid => {
RuleTester.it(invalid.code, () => {
RuleTester.it(sanitize(invalid.code), () => {
testInvalidTemplate(invalid);
});
});
Expand Down
5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -20,8 +20,7 @@
"gensite": "node Makefile.js gensite",
"webpack": "node Makefile.js webpack",
"perf": "node Makefile.js perf",
"profile": "beefy tests/bench/bench.js --open -- -t brfs -t ./tests/bench/xform-rules.js -r espree",
"coveralls": "cat ./coverage/lcov.info | coveralls"
"profile": "beefy tests/bench/bench.js --open -- -t brfs -t ./tests/bench/xform-rules.js -r espree"
},
"gitHooks": {
"pre-commit": "lint-staged"
Expand Down Expand Up @@ -93,7 +92,6 @@
"cheerio": "^0.22.0",
"common-tags": "^1.8.0",
"core-js": "^3.1.3",
"coveralls": "^3.0.3",
"dateformat": "^3.0.3",
"ejs": "^2.6.1",
"eslint": "file:.",
Expand All @@ -118,6 +116,7 @@
"markdownlint-cli": "^0.15.0",
"metro-memory-fs": "^0.53.1",
"mocha": "^6.1.2",
"mocha-junit-reporter": "^1.23.0",
"npm-license": "^0.3.3",
"nyc": "^13.3.0",
"proxyquire": "^2.0.1",
Expand Down
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
};

0 comments on commit 4d75956

Please sign in to comment.