Merge pull request #7484 from loganfsmyth/test-input-mjs
Require tests to use input.mjs for modules, and output.js/.mjs based on active transforms
This commit is contained in:
@@ -67,6 +67,7 @@ export function runSync(
|
||||
ast: opts.ast === true ? file.ast : null,
|
||||
code: outputCode === undefined ? null : outputCode,
|
||||
map: outputMap === undefined ? null : outputMap,
|
||||
sourceType: file.ast.program.sourceType,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -124,6 +124,7 @@ export default function get(entryLoc): Array<Suite> {
|
||||
if (ext !== ".js" && ext !== ".mjs") return;
|
||||
|
||||
execLoc = taskDir;
|
||||
execLocAlias = suiteName + "/" + taskName;
|
||||
}
|
||||
|
||||
if (resolve.relative(expectLoc + "on")) {
|
||||
|
||||
@@ -329,7 +329,10 @@ function run(task) {
|
||||
const newOpts = merge(
|
||||
{
|
||||
filename: self.loc,
|
||||
sourceType: "unambiguous",
|
||||
filenameRelative: self.filename,
|
||||
sourceFileName: self.filename,
|
||||
sourceType: "script",
|
||||
babelrc: false,
|
||||
},
|
||||
opts,
|
||||
);
|
||||
@@ -377,7 +380,15 @@ function run(task) {
|
||||
let actualCode = actual.code;
|
||||
const expectCode = expected.code;
|
||||
if (!execCode || actualCode) {
|
||||
result = babel.transform(actualCode, getOpts(actual));
|
||||
result = babel.transform(
|
||||
actualCode,
|
||||
Object.assign(
|
||||
{
|
||||
sourceMapTarget: task.expect.filename,
|
||||
},
|
||||
getOpts(actual),
|
||||
),
|
||||
);
|
||||
checkDuplicatedNodes(result.ast);
|
||||
if (
|
||||
!expected.code &&
|
||||
@@ -386,11 +397,28 @@ function run(task) {
|
||||
fs.statSync(path.dirname(expected.loc)).isDirectory() &&
|
||||
!process.env.CI
|
||||
) {
|
||||
console.log(`New test file created: ${expected.loc}`);
|
||||
fs.writeFileSync(expected.loc, `${result.code}\n`);
|
||||
const expectedFile = expected.loc.replace(
|
||||
/\.m?js$/,
|
||||
result.sourceType === "module" ? ".mjs" : ".js",
|
||||
);
|
||||
|
||||
console.log(`New test file created: ${expectedFile}`);
|
||||
fs.writeFileSync(expectedFile, `${result.code}\n`);
|
||||
|
||||
if (expected.loc !== expectedFile) {
|
||||
try {
|
||||
fs.unlinkSync(expected.loc);
|
||||
} catch (e) {}
|
||||
}
|
||||
} else {
|
||||
actualCode = result.code.trim();
|
||||
expect(actualCode).toEqual(expectCode);
|
||||
|
||||
if (actualCode) {
|
||||
expect(expected.loc).toMatch(
|
||||
result.sourceType === "module" ? /\.mjs$/ : /\.js$/,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,10 +472,6 @@ export default function(
|
||||
}
|
||||
|
||||
defaults(task.options, {
|
||||
filenameRelative: task.expect.filename,
|
||||
sourceFileName: task.actual.filename,
|
||||
sourceMapTarget: task.expect.filename,
|
||||
babelrc: false,
|
||||
sourceMap: !!(task.sourceMappings || task.sourceMap),
|
||||
});
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user