diff --git a/packages/babel-helper-transform-fixture-test-runner/src/index.ts b/packages/babel-helper-transform-fixture-test-runner/src/index.ts index 459388d7e8..ca938f2497 100644 --- a/packages/babel-helper-transform-fixture-test-runner/src/index.ts +++ b/packages/babel-helper-transform-fixture-test-runner/src/index.ts @@ -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, @@ -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; @@ -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(); - }; - } + let actualLogs; - result = babel.transform(inputCode, getOpts(actual)); - - if (restoreSpies) restoreSpies(); + ({ result, actualLogs } = maybeMockConsole(validateLogs, () => + babel.transform(inputCode, getOpts(actual)), + )); const outputCode = normalizeOutput(result.code); diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/generator-yield/stderr.txt b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/generator-yield/stderr.txt new file mode 100644 index 0000000000..57a1da31d1 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/generator-yield/stderr.txt @@ -0,0 +1 @@ +The smart-mix pipe operator is deprecated. Use "proposal": "hack" instead. diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/hash-tuple/stderr.txt b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/hash-tuple/stderr.txt new file mode 100644 index 0000000000..57a1da31d1 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/hash-tuple/stderr.txt @@ -0,0 +1 @@ +The smart-mix pipe operator is deprecated. Use "proposal": "hack" instead. diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/if-else-block/stderr.txt b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/if-else-block/stderr.txt new file mode 100644 index 0000000000..57a1da31d1 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/if-else-block/stderr.txt @@ -0,0 +1 @@ +The smart-mix pipe operator is deprecated. Use "proposal": "hack" instead. diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/options.json b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/options.json index ffe4feed49..475ac06423 100644 --- a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/options.json +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/options.json @@ -1,3 +1,4 @@ { + "validateLogs": true, "plugins": [["proposal-pipeline-operator", { "proposal": "smart" }]] } diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/pipe-body-with-topic-method-call/stderr.txt b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/pipe-body-with-topic-method-call/stderr.txt new file mode 100644 index 0000000000..57a1da31d1 --- /dev/null +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/smart/pipe-body-with-topic-method-call/stderr.txt @@ -0,0 +1 @@ +The smart-mix pipe operator is deprecated. Use "proposal": "hack" instead. diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/declarations/export-declare-enum/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/declarations/export-declare-enum/input.ts index a5ff19e60d..16fbbe08a3 100644 --- a/packages/babel-plugin-transform-typescript/test/fixtures/declarations/export-declare-enum/input.ts +++ b/packages/babel-plugin-transform-typescript/test/fixtures/declarations/export-declare-enum/input.ts @@ -1,3 +1 @@ export declare enum A {} - -; diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/declarations/export-declare-enum/output.mjs b/packages/babel-plugin-transform-typescript/test/fixtures/declarations/export-declare-enum/output.mjs index 092bc2b041..cb0ff5c3b5 100644 --- a/packages/babel-plugin-transform-typescript/test/fixtures/declarations/export-declare-enum/output.mjs +++ b/packages/babel-plugin-transform-typescript/test/fixtures/declarations/export-declare-enum/output.mjs @@ -1 +1 @@ -; +export {};