From bc36bb39b62c5e9e320551c4f4479ad30f490d34 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sun, 16 Jun 2019 23:49:38 +0900 Subject: [PATCH] improve --- .azure-pipelines/job.yml | 37 +++++++++++++ .gitignore | 1 + Makefile.js | 5 +- azure-pipelines.yml | 96 ++++++++++++---------------------- lib/rule-tester/rule-tester.js | 16 +++++- package.json | 1 + 6 files changed, 90 insertions(+), 66 deletions(-) create mode 100644 .azure-pipelines/job.yml diff --git a/.azure-pipelines/job.yml b/.azure-pipelines/job.yml new file mode 100644 index 000000000000..2f8a55373874 --- /dev/null +++ b/.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 diff --git a/.gitignore b/.gitignore index c65d8d573580..38b7ecd3bf01 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ versions.json .sublimelinterrc .eslint-release-info.json .nyc_output +/test-results.xml diff --git a/Makefile.js b/Makefile.js index b0b54a9a9919..07b31892fc1a 100644 --- a/Makefile.js +++ b/Makefile.js @@ -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++; } diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 552792e8acb2..f72d6d879f82 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -2,67 +2,37 @@ 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 - - task: PublishCodeCoverageResults@1 - inputs: - codeCoverageTool: Cobertura - summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml - reportDirectory: $(System.DefaultWorkingDirectory)/coverage - - - 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 - - task: PublishCodeCoverageResults@1 - inputs: - codeCoverageTool: Cobertura - summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml - reportDirectory: $(System.DefaultWorkingDirectory)/coverage + - template: .azure-pipelines/job.yml + parameters: + name: test_on_linux_node12 + displayName: Test on Linux (Node.js 12) + vmImage: Ubuntu-16.04 + nodeVersion: 12.x - - 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 - - task: PublishCodeCoverageResults@1 - inputs: - codeCoverageTool: Cobertura - summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml - reportDirectory: $(System.DefaultWorkingDirectory)/coverage + - template: .azure-pipelines/job.yml + parameters: + name: test_on_linux_node10 + displayName: Test on Linux (Node.js 10) + vmImage: Ubuntu-16.04 + nodeVersion: 10.x + + - template: .azure-pipelines/job.yml + parameters: + name: test_on_linux_node8 + displayName: Test on Linux (Node.js 8) + vmImage: Ubuntu-16.04 + nodeVersion: 8.x + + - template: .azure-pipelines/job.yml + parameters: + name: test_on_windows_node12 + displayName: Test on Windows (Node.js 12) + vmImage: Windows-2019 + nodeVersion: 12.x + + - template: .azure-pipelines/job.yml + parameters: + name: test_on_macos_node12 + displayName: Test on macOS (Node.js 12) + vmImage: macOS-10.14 + nodeVersion: 12.x diff --git a/lib/rule-tester/rule-tester.js b/lib/rule-tester/rule-tester.js index 30445076a910..81f3a2fc4e7c 100644 --- a/lib/rule-tester/rule-tester.js +++ b/lib/rule-tester/rule-tester.js @@ -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 //------------------------------------------------------------------------------ @@ -613,7 +625,7 @@ 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); }); }); @@ -621,7 +633,7 @@ class RuleTester { RuleTester.describe("invalid", () => { test.invalid.forEach(invalid => { - RuleTester.it(invalid.code, () => { + RuleTester.it(sanitize(invalid.code), () => { testInvalidTemplate(invalid); }); }); diff --git a/package.json b/package.json index 3a177d3b0c29..6e462ddac74e 100644 --- a/package.json +++ b/package.json @@ -118,6 +118,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",