Skip to content

Commit

Permalink
test: add test for babel --filename on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 26, 2019
1 parent 1ab4a6e commit cba606b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
@@ -0,0 +1,5 @@
{
"args": ["--filename", "test.js"],
"stderrContains": true,
"nodePlatform": ["win32"]
}
@@ -0,0 +1 @@
SyntaxError: <CWD>\test.js: Unexpected token, expected ";" (2:10)
@@ -0,0 +1,3 @@
arr.map(function () {
return $]!;
});
@@ -1,4 +1,5 @@
{
"args": ["--filename", "test.js"],
"stderrContains": true
"stderrContains": true,
"nodePlatform": ["linux", "darwin"]
}
27 changes: 26 additions & 1 deletion packages/babel-cli/test/index.js
Expand Up @@ -185,7 +185,32 @@ fs.readdirSync(fixtureLoc).forEach(function(binName) {
};

const optionsLoc = path.join(testLoc, "options.json");
if (fs.existsSync(optionsLoc)) merge(opts, require(optionsLoc));
if (fs.existsSync(optionsLoc)) {
const taskOpts = require(optionsLoc);
if (taskOpts.nodePlatform) {
let nodePlatform = taskOpts.nodePlatform;

if (
!Array.isArray(nodePlatform) &&
typeof nodePlatform !== "string"
) {
throw new Error(
`'nodePlatform' should be either string or string array: ${taskOpts.nodePlatform}`,
);
}

if (typeof nodePlatform === "string") {
nodePlatform = [nodePlatform];
}

if (!nodePlatform.includes(process.platform)) {
return;
}

delete taskOpts.nodePlatform;
}
merge(opts, taskOpts);
}

["stdout", "stdin", "stderr"].forEach(function(key) {
const loc = path.join(testLoc, key + ".txt");
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-helper-fixtures/src/index.js
Expand Up @@ -195,7 +195,7 @@ export default function get(entryLoc): Array<Suite> {
if (taskOpts.nodePlatform) {
let nodePlatform = taskOpts.nodePlatform;

if (!nodePlatform) {
if (!Array.isArray(nodePlatform) && typeof nodePlatform !== "string") {
throw new Error(
`'nodePlatform' should be either string or string array: ${taskOpts.nodePlatform}`,
);
Expand Down
@@ -1,4 +1,4 @@
{
"presets": [["react", { "development": true }]],
"nodePlatform": ["windows"]
"nodePlatform": ["win32"]
}

0 comments on commit cba606b

Please sign in to comment.