Minor updates after merging 7.15.0 PRs (#13628)

This commit is contained in:
Nicolò Ribaudo 2021-08-04 15:38:10 +02:00 committed by GitHub
parent 70c66b3799
commit fc3b09e533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 21 deletions

View File

@ -196,6 +196,26 @@ export function runCodeInTestContext(
} }
} }
function maybeMockConsole(validateLogs, run) {
const actualLogs = { stdout: "", stderr: "" };
if (!validateLogs) return { result: run(), actualLogs };
const spy1 = jest.spyOn(console, "log").mockImplementation(msg => {
actualLogs.stdout += `${msg}\n`;
});
const spy2 = jest.spyOn(console, "warn").mockImplementation(msg => {
actualLogs.stderr += `${msg}\n`;
});
try {
return { result: run(), actualLogs };
} finally {
spy1.mockRestore();
spy2.mockRestore();
}
}
function run(task) { function run(task) {
const { const {
actual, actual,
@ -234,7 +254,13 @@ function run(task) {
if (execCode) { if (execCode) {
const context = createContext(); const context = createContext();
const execOpts = getOpts(exec); const execOpts = getOpts(exec);
result = babel.transform(execCode, execOpts);
// Ignore Babel logs of exec.js files.
// They will be validated in input/output files.
({ result } = maybeMockConsole(validateLogs, () =>
babel.transform(execCode, execOpts),
));
checkDuplicatedNodes(babel, result.ast); checkDuplicatedNodes(babel, result.ast);
execCode = result.code; execCode = result.code;
@ -251,24 +277,11 @@ function run(task) {
const inputCode = actual.code; const inputCode = actual.code;
const expectedCode = expected.code; const expectedCode = expected.code;
if (!execCode || inputCode) { if (!execCode || inputCode) {
const actualLogs = { stdout: "", stderr: "" }; let actualLogs;
let restoreSpies = null;
if (validateLogs) {
const spy1 = jest.spyOn(console, "log").mockImplementation(msg => {
actualLogs.stdout += `${msg}\n`;
});
const spy2 = jest.spyOn(console, "warn").mockImplementation(msg => {
actualLogs.stderr += `${msg}\n`;
});
restoreSpies = () => {
spy1.mockRestore();
spy2.mockRestore();
};
}
result = babel.transform(inputCode, getOpts(actual)); ({ result, actualLogs } = maybeMockConsole(validateLogs, () =>
babel.transform(inputCode, getOpts(actual)),
if (restoreSpies) restoreSpies(); ));
const outputCode = normalizeOutput(result.code); const outputCode = normalizeOutput(result.code);

View File

@ -0,0 +1 @@
The smart-mix pipe operator is deprecated. Use "proposal": "hack" instead.

View File

@ -0,0 +1 @@
The smart-mix pipe operator is deprecated. Use "proposal": "hack" instead.

View File

@ -0,0 +1 @@
The smart-mix pipe operator is deprecated. Use "proposal": "hack" instead.

View File

@ -1,3 +1,4 @@
{ {
"validateLogs": true,
"plugins": [["proposal-pipeline-operator", { "proposal": "smart" }]] "plugins": [["proposal-pipeline-operator", { "proposal": "smart" }]]
} }

View File

@ -0,0 +1 @@
The smart-mix pipe operator is deprecated. Use "proposal": "hack" instead.

View File

@ -1,3 +1 @@
export declare enum A {} export declare enum A {}
;