Fix tests for Windows and add Azure Pipelines for cross platform CI (#5410)

* Add azure pipelines

* Add gitattributes

* Updating tests to work on Windows or Unix

* Lint

* Cleaning up

* Fixing names

* Clean up naming

* try to consolidate images

* Clean up

* Add back txt to gitattributes
master
Danny McCormick 2018-11-14 07:55:50 -05:00 committed by Jed Fox
parent 57b057cfa2
commit 18b03a31cc
33 changed files with 403 additions and 137 deletions

4
.gitattributes vendored Normal file
View File

@ -0,0 +1,4 @@
# Make sure baseline files have consistent line endings
*.txt text eol=lf
*.snap text eol=lf
*.debug-check text eol=lf

19
azure-pipelines-tests.yml Normal file
View File

@ -0,0 +1,19 @@
steps:
- task: NodeTool@0
inputs:
versionSpec: '$(node_version)'
displayName: 'Install Node.js'
- script: npm install -g yarn
displayName: 'Get yarn'
- script: yarn install
displayName: 'yarn install'
- script: yarn test
displayName: 'Test'
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/junit.xml'
condition: succeededOrFailed()

109
azure-pipelines.yml Normal file
View File

@ -0,0 +1,109 @@
trigger:
- master
- releases/*
jobs:
# Build and test on Windows
- job: Test_Windows
displayName: Tests on Windows Node8
pool:
vmImage: vs2017-win2016
variables:
node_version: 8.x
report_summaries: true
steps:
- template: azure-pipelines-tests.yml
# Build and test on macOS
- job: Test_macOS
displayName: Tests on macOS Node8
pool:
vmImage: macos-10.13
variables:
node_version: 8.x
report_summaries: true
steps:
- template: azure-pipelines-tests.yml
# Test on Linux
- job: Test_Linux
displayName: Run tests
pool:
vmImage: 'Ubuntu 16.04'
strategy:
matrix:
Node8:
node_version: '8.x'
Node11:
node_version: '11.x'
variables:
report_summaries: true
steps:
- template: azure-pipelines-tests.yml
# Test production bundle on Linux using Node 4
- job: Prod_Linux
displayName: Test production bundle on Linux
pool:
vmImage: 'Ubuntu 16.04'
strategy:
matrix:
Node4:
node_version: '4.x'
Node9:
node_version: '9.x'
steps:
- task: NodeTool@0
inputs:
versionSpec: '11.x'
displayName: 'Install Node.js'
- script: npm install -g yarn
displayName: 'Get yarn'
- script: yarn install
displayName: 'yarn install'
- script: yarn check-deps
displayName: 'Check dependencies'
- script: yarn build
displayName: 'Build'
- task: NodeTool@0
inputs:
versionSpec: '$(node_version)'
displayName: 'Use Node.js $(node_version)'
- script: npm install -g yarn@1.5
displayName: 'Get yarn compatible with node 4'
condition: eq(variables['node_version'], '4.x')
- script: node ./scripts/test-dist.js
displayName: 'Test'
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/junit.xml'
condition: and(variables['report_summaries'], succeededOrFailed())
# Lint checks on Linux
- job: Lint_linux
displayName: Lint (Linux)
pool:
vmImage: 'Ubuntu 16.04'
steps:
- task: NodeTool@0
inputs:
versionSpec: '8.x'
displayName: 'Install Node.js'
- script: yarn install
displayName: 'yarn install'
- script: yarn lint
displayName: 'Lint code'
- script: yarn lint-docs
displayName: 'Lint docs'

View File

@ -17,9 +17,13 @@ module.exports = {
"jest-snapshot-serializer-ansi"
],
testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$",
testPathIgnorePatterns: ["tests/new_react", "tests/more_react"].concat(
isOldNode ? requiresPrettierInternals : []
),
testPathIgnorePatterns: ["tests/new_react", "tests/more_react"]
.concat(isOldNode ? requiresPrettierInternals : [])
.concat(
require("os").EOL == "\n"
? ["tests_integration/__tests__/eol-crlf.js"]
: ["tests_integration/__tests__/eol-lf.js"]
),
collectCoverage: ENABLE_COVERAGE,
collectCoverageFrom: ["src/**/*.js", "index.js", "!<rootDir>/node_modules/"],
coveragePathIgnorePatterns: [

View File

@ -1,35 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`line-ending.js - flow-verify 1`] = `
this;
has;
windows;
line;
endings;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this;
has;
windows;
line;
endings;
`;
exports[`template.js - flow-verify 1`] = `
const aLongString = \`
Line 1
Line 2
Line 3
Line 4
Line 5
\`;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const aLongString = \`
Line 1
Line 2
Line 3
Line 4
Line 5
\`;
`;

View File

@ -1 +0,0 @@
run_spec(__dirname, ["flow", "typescript"]);

View File

@ -1,5 +0,0 @@
this;
has;
windows;
line;
endings;

View File

@ -1,7 +0,0 @@
const aLongString = `
Line 1
Line 2
Line 3
Line 4
Line 5
`;

View File

@ -3,17 +3,7 @@
exports[`CLI overrides take precedence (stderr) 1`] = `""`;
exports[`CLI overrides take precedence (stdout) 1`] = `
"function f() {/*CR*/ console.log(/*CR*/ \\"line endings should be CR\\"/*CR*/ )/*CR*/}/*CR*/function f() {/*CR*/
console.log(/*CR*/
\\"line endings should be CRLF\\"/*CR*/
)/*CR*/
}/*CR*/
function f() {
console.log(
\\"line endings should be LF\\"
)
}
function f() {
"function f() {
console.log(
\\"should have tab width 8\\"
)
@ -50,6 +40,8 @@ function js() {
\\"use strict\\";
module.exports = {
endOfLine:
\\"lf\\",
tabWidth: 8
};
function noConfigJs() {
@ -124,13 +116,7 @@ exports[`resolves configuration file with --find-config-path file (write) 1`] =
exports[`resolves configuration from external files (stderr) 1`] = `""`;
exports[`resolves configuration from external files (stdout) 1`] = `
"function f() {/*CR*/ console.log(\\"line endings should be CR\\")/*CR*/}/*CR*/function f() {/*CR*/
console.log(\\"line endings should be CRLF\\")/*CR*/
}/*CR*/
function f() {
console.log(\\"line endings should be LF\\")
}
function f() {
"function f() {
console.log(\\"should have tab width 8\\")
}
function f() {
@ -153,6 +139,7 @@ function js() {
\\"use strict\\";
module.exports = {
endOfLine: \\"lf\\",
tabWidth: 8
};
function noConfigJs() {

View File

@ -0,0 +1,62 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Has correct default Windows line endings (stderr) 1`] = `""`;
exports[`Has correct default Windows line endings (stdout) 1`] = `
"function f() {
console.log(\\"should have tab width 8\\")
}
function f() {
console.log(\\"should have space width 2\\")
}
function f() {
console.log(\\"should have space width 8\\")
}
function f() {
console.log(
\\"should have space width 2 despite ../.editorconfig specifying 8, because ./.hg is present\\"
)
}
console.log(\\"jest/__best-tests__/file.js should have semi\\");/*CR*/
console.log(\\"jest/Component.js should not have semi\\")/*CR*/
console.log(\\"jest/Component.test.js should have semi\\");/*CR*/
function js() {
console.log(\\"js/file.js should have tab width 8 (1 if CLI)\\");
}
\\"use strict\\";
module.exports = {
endOfLine: \\"lf\\",
tabWidth: 8
};
function noConfigJs() {
console.log(\\"no-config/file.js should have no semicolons\\")
}
function packageJs() {/*CR*/
console.log(\\"package/file.js should have tab width 3\\");/*CR*/
}/*CR*/
function rcJson() {/*CR*/
console.log.apply(null, [/*CR*/
'rc-json/file.js',/*CR*/
'should have trailing comma',/*CR*/
'and single quotes',/*CR*/
]);/*CR*/
}/*CR*/
function rcToml() {/*CR*/
console.log.apply(null, [/*CR*/
'rc-toml/file.js',/*CR*/
'should have trailing comma',/*CR*/
'and single quotes',/*CR*/
]);/*CR*/
}/*CR*/
function rcYaml() {/*CR*/
console.log.apply(null, [/*CR*/
'rc-yaml/file.js',/*CR*/
'should have trailing comma',/*CR*/
'and single quotes',/*CR*/
]);/*CR*/
}/*CR*/
"
`;
exports[`Has correct default Windows line endings (write) 1`] = `Array []`;

View File

@ -0,0 +1,62 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Has correct default Unix line endings (stderr) 1`] = `""`;
exports[`Has correct default Unix line endings (stdout) 1`] = `
"function f() {
console.log(\\"should have tab width 8\\")
}
function f() {
console.log(\\"should have space width 2\\")
}
function f() {
console.log(\\"should have space width 8\\")
}
function f() {
console.log(
\\"should have space width 2 despite ../.editorconfig specifying 8, because ./.hg is present\\"
)
}
console.log(\\"jest/__best-tests__/file.js should have semi\\");
console.log(\\"jest/Component.js should not have semi\\")
console.log(\\"jest/Component.test.js should have semi\\");
function js() {
console.log(\\"js/file.js should have tab width 8 (1 if CLI)\\");
}
\\"use strict\\";
module.exports = {
endOfLine: \\"lf\\",
tabWidth: 8
};
function noConfigJs() {
console.log(\\"no-config/file.js should have no semicolons\\")
}
function packageJs() {
console.log(\\"package/file.js should have tab width 3\\");
}
function rcJson() {
console.log.apply(null, [
'rc-json/file.js',
'should have trailing comma',
'and single quotes',
]);
}
function rcToml() {
console.log.apply(null, [
'rc-toml/file.js',
'should have trailing comma',
'and single quotes',
]);
}
function rcYaml() {
console.log.apply(null, [
'rc-yaml/file.js',
'should have trailing comma',
'and single quotes',
]);
}
"
`;
exports[`Has correct default Unix line endings (write) 1`] = `Array []`;

View File

@ -54,6 +54,7 @@ exports[`CLI overrides gets ignored when config exists with --config-precedence
\\"use strict\\";
module.exports = {
endOfLine: \\"lf\\",
tabWidth: 8
};
"
@ -70,6 +71,7 @@ exports[`CLI overrides take lower precedence with --config-precedence file-overr
\\"use strict\\";
module.exports = {
endOfLine: \\"lf\\",
tabWidth: 8
};
"
@ -80,17 +82,7 @@ exports[`CLI overrides take lower precedence with --config-precedence file-overr
exports[`CLI overrides take precedence with --config-precedence cli-override (stderr) 1`] = `""`;
exports[`CLI overrides take precedence with --config-precedence cli-override (stdout) 1`] = `
"function f() {/*CR*/ console.log(/*CR*/ \\"line endings should be CR\\"/*CR*/ )/*CR*/}/*CR*/function f() {/*CR*/
console.log(/*CR*/
\\"line endings should be CRLF\\"/*CR*/
)/*CR*/
}/*CR*/
function f() {
console.log(
\\"line endings should be LF\\"
)
}
function f() {
"function f() {
console.log(
\\"should have tab width 8\\"
)
@ -127,6 +119,8 @@ function js() {
\\"use strict\\";
module.exports = {
endOfLine:
\\"lf\\",
tabWidth: 8
};
function noConfigJs() {
@ -177,17 +171,7 @@ exports[`CLI overrides take precedence with --config-precedence cli-override (wr
exports[`CLI overrides take precedence without --config-precedence (stderr) 1`] = `""`;
exports[`CLI overrides take precedence without --config-precedence (stdout) 1`] = `
"function f() {/*CR*/ console.log(/*CR*/ \\"line endings should be CR\\"/*CR*/ )/*CR*/}/*CR*/function f() {/*CR*/
console.log(/*CR*/
\\"line endings should be CRLF\\"/*CR*/
)/*CR*/
}/*CR*/
function f() {
console.log(
\\"line endings should be LF\\"
)
}
function f() {
"function f() {
console.log(
\\"should have tab width 8\\"
)
@ -224,6 +208,8 @@ function js() {
\\"use strict\\";
module.exports = {
endOfLine:
\\"lf\\",
tabWidth: 8
};
function noConfigJs() {

View File

@ -3,37 +3,67 @@
const runPrettier = require("../runPrettier");
describe("boolean flags do not swallow the next argument", () => {
runPrettier("cli/arg-parsing", ["--single-quote", "file.js"]).test({
runPrettier("cli/arg-parsing", [
"--end-of-line",
"lf",
"--single-quote",
"file.js"
]).test({
status: 0
});
});
describe("negated options work", () => {
runPrettier("cli/arg-parsing", ["--no-semi", "file.js"]).test({
runPrettier("cli/arg-parsing", [
"--end-of-line",
"lf",
"--no-semi",
"file.js"
]).test({
status: 0
});
});
describe("unknown options are warned", () => {
runPrettier("cli/arg-parsing", ["file.js", "--unknown"]).test({
runPrettier("cli/arg-parsing", [
"--end-of-line",
"lf",
"file.js",
"--unknown"
]).test({
status: 0
});
});
describe("unknown negated options are warned", () => {
runPrettier("cli/arg-parsing", ["file.js", "--no-unknown"]).test({
runPrettier("cli/arg-parsing", [
"--end-of-line",
"lf",
"file.js",
"--no-unknown"
]).test({
status: 0
});
});
describe("deprecated options are warned", () => {
runPrettier("cli/arg-parsing", ["file.js", "--flow-parser"]).test({
runPrettier("cli/arg-parsing", [
"--end-of-line",
"lf",
"file.js",
"--flow-parser"
]).test({
status: 0
});
});
describe("deprecated option values are warned", () => {
runPrettier("cli/arg-parsing", ["file.js", "--trailing-comma"]).test({
runPrettier("cli/arg-parsing", [
"--end-of-line",
"lf",
"file.js",
"--trailing-comma"
]).test({
status: 0
});
});

View File

@ -8,13 +8,13 @@ const prettier = require("prettier/local");
expect.addSnapshotSerializer(require("../path-serializer"));
describe("resolves configuration from external files", () => {
runPrettier("cli/config/", ["**/*.js"]).test({
runPrettier("cli/config/", ["--end-of-line", "lf", "**/*.js"]).test({
status: 0
});
});
describe("resolves configuration from external files and overrides by extname", () => {
runPrettier("cli/config/", ["**/*.ts"]).test({
runPrettier("cli/config/", ["--end-of-line", "lf", "**/*.ts"]).test({
status: 0
});
});
@ -50,14 +50,25 @@ describe("resolves toml configuration file with --find-config-path file", () =>
});
describe("prints nothing when no file found with --find-config-path", () => {
runPrettier("cli/config/", ["--find-config-path", ".."]).test({
runPrettier("cli/config/", [
"--end-of-line",
"lf",
"--find-config-path",
".."
]).test({
stdout: "",
status: 1
});
});
describe("CLI overrides take precedence", () => {
runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]).test({
runPrettier("cli/config/", [
"--end-of-line",
"lf",
"--print-width",
"1",
"**/*.js"
]).test({
status: 0
});
});

View File

@ -22,6 +22,8 @@ describe("checks stdin with --debug-check", () => {
describe("show diff for 2+ error files with --debug-check", () => {
runPrettier("cli/debug-check", [
"--end-of-line",
"lf",
"*.debug-check",
"--debug-check",
"--plugin",

View File

@ -0,0 +1,11 @@
"use strict";
const runPrettier = require("../runPrettier");
expect.addSnapshotSerializer(require("../path-serializer"));
describe("Has correct default Windows line endings", () => {
runPrettier("cli/config/", ["**/*.js"]).test({
status: 0
});
});

View File

@ -0,0 +1,11 @@
"use strict";
const runPrettier = require("../runPrettier");
expect.addSnapshotSerializer(require("../path-serializer"));
describe("Has correct default Unix line endings", () => {
runPrettier("cli/config/", ["**/*.js"]).test({
status: 0
});
});

View File

@ -26,7 +26,9 @@ describe("ignore file when using --debug-check", () => {
});
describe("outputs files as-is if no --write", () => {
runPrettier("cli/ignore-path", ["regular-module.js"]).test({
runPrettier("cli/ignore-path", ["regular-module.js"], {
ignoreLineEndings: true
}).test({
status: 0
});
});

View File

@ -49,7 +49,7 @@ describe("stdin with unknown path and no parser", () => {
describe("unknown path and no parser", () => {
describe("specific file", () => {
runPrettier("cli/infer-parser/", ["FOO"]).test({
runPrettier("cli/infer-parser/", ["--end-of-line", "lf", "FOO"]).test({
status: 2,
stdout: "",
write: []
@ -57,7 +57,7 @@ describe("unknown path and no parser", () => {
});
describe("multiple files", () => {
runPrettier("cli/infer-parser/", ["*"]).test({
runPrettier("cli/infer-parser/", ["--end-of-line", "lf", "*"]).test({
status: 2,
write: []
});

View File

@ -31,6 +31,8 @@ test("allows usage of prettier's supported parsers", () => {
describe("allows passing a string to resolve a parser", () => {
runPrettier("./custom-parsers/", [
"--end-of-line",
"lf",
"./custom-rename-input.js",
"--parser",
"./custom-rename-parser"

View File

@ -4,7 +4,9 @@ const runPrettier = require("../runPrettier");
const EOL = "\n";
describe("uses 'extensions' from languages to determine parser", () => {
runPrettier("plugins/extensions", ["*.foo", "--plugin=./plugin"]).test({
runPrettier("plugins/extensions", ["*.foo", "--plugin=./plugin"], {
ignoreLineEndings: true
}).test({
stdout: "!contents" + EOL,
stderr: "",
status: 0,

View File

@ -4,7 +4,9 @@ const runPrettier = require("../runPrettier");
const EOL = "\n";
describe("parser preprocess function is used to reshape input text", () => {
runPrettier("plugins/preprocess", ["*.foo", "--plugin=./plugin"]).test({
runPrettier("plugins/preprocess", ["*.foo", "--plugin=./plugin"], {
ignoreLineEndings: true
}).test({
stdout: "preprocessed:contents" + EOL,
stderr: "",
status: 0,

View File

@ -74,11 +74,17 @@ describe("automatically loads '@prettier/plugin-*' from --plugin-search-dir (dif
});
describe("does not crash when --plugin-search-dir does not contain node_modules", () => {
runPrettier("plugins/extensions", [
"file.foo",
"--plugin=./plugin",
"--plugin-search-dir=."
]).test({
runPrettier(
"plugins/extensions",
[
"file.foo",
"--end-of-line",
"lf",
"--plugin=./plugin",
"--plugin-search-dir=."
],
{ ignoreLineEndings: true }
).test({
stdout: "!contents" + EOL,
stderr: "",
status: 0,

View File

@ -3,13 +3,21 @@
const runPrettier = require("../runPrettier");
describe("CLI overrides take precedence without --config-precedence", () => {
runPrettier("cli/config/", ["--print-width", "1", "**/*.js"]).test({
runPrettier("cli/config/", [
"--end-of-line",
"lf",
"--print-width",
"1",
"**/*.js"
]).test({
status: 0
});
});
describe("CLI overrides take precedence with --config-precedence cli-override", () => {
runPrettier("cli/config/", [
"--end-of-line",
"lf",
"--print-width",
"1",
"--config-precedence",
@ -22,6 +30,8 @@ describe("CLI overrides take precedence with --config-precedence cli-override",
describe("CLI overrides take lower precedence with --config-precedence file-override", () => {
runPrettier("cli/config/js/", [
"--end-of-line",
"crlf",
"--tab-width",
"1",
"--config-precedence",
@ -34,6 +44,8 @@ describe("CLI overrides take lower precedence with --config-precedence file-over
describe("CLI overrides are still applied when no config is found with --config-precedence file-override", () => {
runPrettier("cli/config/no-config/", [
"--end-of-line",
"lf",
"--tab-width",
"6",
"--config-precedence",
@ -60,6 +72,8 @@ describe("CLI overrides gets ignored when config exists with --config-precedence
describe("CLI overrides gets applied when no config exists with --config-precedence prefer-file", () => {
runPrettier("cli/config/no-config/", [
"--end-of-line",
"lf",
"--print-width",
"1",
"--tab-width",

View File

@ -4,7 +4,7 @@ const runPrettier = require("../runPrettier");
const prettier = require("prettier/local");
describe("infers postcss parser", () => {
runPrettier("cli/with-parser-inference", ["*"]).test({
runPrettier("cli/with-parser-inference", ["--end-of-line", "lf", "*"]).test({
status: 0
});
});

View File

@ -3,7 +3,9 @@
const runPrettier = require("../runPrettier");
describe("preserves shebang", () => {
runPrettier("cli/with-shebang", ["issue1890.js"]).test({
status: 0
});
runPrettier("cli/with-shebang", ["--end-of-line", "lf", "issue1890.js"]).test(
{
status: 0
}
);
});

View File

@ -1,3 +1,4 @@
endOfLine: 'lf'
overrides:
- files: "*.js"
options:

View File

@ -12,14 +12,4 @@ indent_style = space
indent_size = 2
[lib/indent_size=tab.js]
indent_size = tab
# End of line (--eol opition)
[eol/cr.js]
end_of_line = cr
[eol/crlf.js]
end_of_line = crlf
[eol/lf.js]
end_of_line = lf
indent_size = tab

View File

@ -1,3 +0,0 @@
function f() {
console.log("line endings should be CR")
}

View File

@ -1,3 +0,0 @@
function f() {
console.log("line endings should be CRLF")
}

View File

@ -1,3 +0,0 @@
function f() {
console.log("line endings should be LF")
}

View File

@ -1,5 +1,6 @@
"use strict";
module.exports = {
endOfLine: 'lf',
tabWidth: 8
};

View File

@ -111,8 +111,11 @@ function runPrettier(dir, args, options) {
const value =
// \r is trimmed from jest snapshots by default;
// manually replacing this character with /*CR*/ to test its true presence
// If ignoreLineEndings is specified, \r is simply deleted instead
typeof result[name] === "string"
? stripAnsi(result[name]).replace(/\r/g, "/*CR*/")
? options.ignoreLineEndings
? stripAnsi(result[name]).replace(/\r/g, "")
: stripAnsi(result[name]).replace(/\r/g, "/*CR*/")
: result[name];
if (name in testOptions) {
if (name === "status" && testOptions[name] === "non-zero") {