From 30231744cba0a46a96458b517c1666ed31724f94 Mon Sep 17 00:00:00 2001 From: "compulim-workflow-bot[bot]" <145930250+compulim-workflow-bot[bot]@users.noreply.github.com> Date: Sun, 24 Sep 2023 23:38:24 -0700 Subject: [PATCH] Bump scaffold (#24) * Remove unnecessary config * Revert * Add typingTestTransformer * Rename to __tests__ * Rename to __tests__ * Bump scaffold * Add entrypoint --------- Co-authored-by: William Wong Co-authored-by: @compulim <@compulim> --- packages/integration-test/jest.config.json | 27 +++++++++--- .../__setup__/createDeferred.ts | 0 .../__setup__/typingTestTransformer.js | 41 +++++++++++++++++++ .../__setup__/waitFor.ts | 0 .../{__test__ => __tests__}/waitFor.spec.ts | 0 .../message-port-rpc/babel.jest.config.json | 15 ------- packages/message-port-rpc/jest.config.json | 25 ++++++++++- .../src/messagePortRPC.spec.ts | 4 +- 8 files changed, 88 insertions(+), 24 deletions(-) rename packages/message-port-rpc/{__test__ => __tests__}/__setup__/createDeferred.ts (100%) create mode 100644 packages/message-port-rpc/__tests__/__setup__/typingTestTransformer.js rename packages/message-port-rpc/{__test__ => __tests__}/__setup__/waitFor.ts (100%) rename packages/message-port-rpc/{__test__ => __tests__}/waitFor.spec.ts (100%) delete mode 100644 packages/message-port-rpc/babel.jest.config.json diff --git a/packages/integration-test/jest.config.json b/packages/integration-test/jest.config.json index 6da95ea..f15ada2 100644 --- a/packages/integration-test/jest.config.json +++ b/packages/integration-test/jest.config.json @@ -1,9 +1,26 @@ { - "testMatch": [ - "**/__tests__/**/*.?([cm])[jt]s?(x)", - "**/?(*.)+(spec|test).?([cm])[tj]s?(x)" - ], + "testMatch": ["**/__tests__/**/*.?([cm])[jt]s?(x)", "**/?(*.)+(spec|test).?([cm])[jt]s?(x)"], "transform": { - "\\.mjsx?$": ["babel-jest"] + "\\.cjsx?$": [ + "babel-jest", + { + "presets": ["@babel/preset-react"] + } + ], + "\\.mjsx?$": [ + "babel-jest", + { + "presets": [ + "@babel/preset-react", + [ + "@babel/preset-env", + { + "modules": "commonjs", + "targets": "defaults" + } + ] + ] + } + ] } } diff --git a/packages/message-port-rpc/__test__/__setup__/createDeferred.ts b/packages/message-port-rpc/__tests__/__setup__/createDeferred.ts similarity index 100% rename from packages/message-port-rpc/__test__/__setup__/createDeferred.ts rename to packages/message-port-rpc/__tests__/__setup__/createDeferred.ts diff --git a/packages/message-port-rpc/__tests__/__setup__/typingTestTransformer.js b/packages/message-port-rpc/__tests__/__setup__/typingTestTransformer.js new file mode 100644 index 0000000..f332d09 --- /dev/null +++ b/packages/message-port-rpc/__tests__/__setup__/typingTestTransformer.js @@ -0,0 +1,41 @@ +// Notes: to test changes in this file, run "jest" with "--no-cache" argument. + +const run = ({ filename }) => { + const typeScript = require('typescript'); + + function compile(...filenames) { + const program = typeScript.createProgram(filenames, { + allowSyntheticDefaultImports: true, + jsx: typeScript.JsxEmit.React, + noEmit: true, + skipLibCheck: true, + strict: true + }); + + const emitResult = program.emit(); + const allDiagnostics = typeScript.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); + + allDiagnostics.forEach(({ file, messageText, start }) => { + if (file && start) { + const { line, character } = file.getLineAndCharacterOfPosition(start); + const message = typeScript.flattenDiagnosticMessageText(messageText, '\n'); + + throw new Error(`Failed to compile ${file.fileName} (${line + 1},${character + 1}): ${message}`); + } else { + throw new Error(typeScript.flattenDiagnosticMessageText(messageText, '\n')); + } + }); + } + + if (filename.includes('fail')) { + test(`Compile ${filename} should fail`, () => expect(() => compile(filename)).toThrow()); + } else { + test(`Compile ${filename} should succeed`, () => compile(filename)); + } +}; + +module.exports = { + process(_, filename) { + return { code: `(${run})(${JSON.stringify({ filename })})` }; + } +}; diff --git a/packages/message-port-rpc/__test__/__setup__/waitFor.ts b/packages/message-port-rpc/__tests__/__setup__/waitFor.ts similarity index 100% rename from packages/message-port-rpc/__test__/__setup__/waitFor.ts rename to packages/message-port-rpc/__tests__/__setup__/waitFor.ts diff --git a/packages/message-port-rpc/__test__/waitFor.spec.ts b/packages/message-port-rpc/__tests__/waitFor.spec.ts similarity index 100% rename from packages/message-port-rpc/__test__/waitFor.spec.ts rename to packages/message-port-rpc/__tests__/waitFor.spec.ts diff --git a/packages/message-port-rpc/babel.jest.config.json b/packages/message-port-rpc/babel.jest.config.json deleted file mode 100644 index cdac463..0000000 --- a/packages/message-port-rpc/babel.jest.config.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "presets": [ - "@babel/preset-typescript", - [ - "@babel/preset-env", - { - "modules": "commonjs", - "targets": { - "node": "18" - } - } - ] - ], - "sourceMaps": true -} diff --git a/packages/message-port-rpc/jest.config.json b/packages/message-port-rpc/jest.config.json index 9b78821..c6d77d7 100644 --- a/packages/message-port-rpc/jest.config.json +++ b/packages/message-port-rpc/jest.config.json @@ -1,10 +1,31 @@ { - "testPathIgnorePatterns": ["/__tests__/__setup__/", "/lib/", "/node_modules/", "/__types__/", "\\.pnp\\.[^\\/]+$"], + "testPathIgnorePatterns": [ + "/__tests__/__setup__/", + "/lib/", + "/node_modules/", + "/__types__/", + "\\.pnp\\.[^\\/]+$" + ], "transform": { + "/__tests__/types/": [ + "/__tests__/__setup__/typingTestTransformer.js" + ], "\\.[jt]sx?$": [ "babel-jest", { - "extends": "./babel.jest.config.json" + "presets": [ + "@babel/preset-typescript", + [ + "@babel/preset-env", + { + "modules": "commonjs", + "targets": { + "node": "18" + } + } + ] + ], + "sourceMaps": true } ] } diff --git a/packages/message-port-rpc/src/messagePortRPC.spec.ts b/packages/message-port-rpc/src/messagePortRPC.spec.ts index 3bb018b..656406a 100644 --- a/packages/message-port-rpc/src/messagePortRPC.spec.ts +++ b/packages/message-port-rpc/src/messagePortRPC.spec.ts @@ -1,8 +1,8 @@ import { afterEach, beforeEach, describe, expect, jest, test } from '@jest/globals'; -import createDeferred from '../__test__/__setup__/createDeferred'; +import createDeferred from '../__tests__/__setup__/createDeferred'; import messagePortRPC from './messagePortRPC'; -import waitFor from '../__test__/__setup__/waitFor'; +import waitFor from '../__tests__/__setup__/waitFor'; type Fn = (x: number, y: number) => Promise; type MockFn = jest.Mock;