Skip to content

Commit

Permalink
Minor updates after merging 7.15.0 PRs (#13628)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Aug 4, 2021
1 parent 70c66b3 commit fc3b09e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 21 deletions.
49 changes: 31 additions & 18 deletions packages/babel-helper-transform-fixture-test-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
const {
actual,
Expand Down Expand Up @@ -234,7 +254,13 @@ function run(task) {
if (execCode) {
const context = createContext();
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);
execCode = result.code;

Expand All @@ -251,24 +277,11 @@ function run(task) {
const inputCode = actual.code;
const expectedCode = expected.code;
if (!execCode || inputCode) {
const actualLogs = { stdout: "", stderr: "" };
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));
let actualLogs;

if (restoreSpies) restoreSpies();
({ result, actualLogs } = maybeMockConsole(validateLogs, () =>
babel.transform(inputCode, getOpts(actual)),
));

const outputCode = normalizeOutput(result.code);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The smart-mix pipe operator is deprecated. Use "proposal": "hack" instead.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The smart-mix pipe operator is deprecated. Use "proposal": "hack" instead.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The smart-mix pipe operator is deprecated. Use "proposal": "hack" instead.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"validateLogs": true,
"plugins": [["proposal-pipeline-operator", { "proposal": "smart" }]]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The smart-mix pipe operator is deprecated. Use "proposal": "hack" instead.
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export declare enum A {}

;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
;
export {};

0 comments on commit fc3b09e

Please sign in to comment.