Skip to content

Commit

Permalink
Bump scaffold (#24)
Browse files Browse the repository at this point in the history
* Remove unnecessary config

* Revert

* Add typingTestTransformer

* Rename to __tests__

* Rename to __tests__

* Bump scaffold

* Add entrypoint

---------

Co-authored-by: William Wong <compulim@hotmail.com>
Co-authored-by: @compulim <@compulim>
  • Loading branch information
compulim-workflow-bot[bot] and compulim authored Sep 25, 2023
1 parent e99cfe8 commit 3023174
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 24 deletions.
27 changes: 22 additions & 5 deletions packages/integration-test/jest.config.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -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 })})` };
}
};
15 changes: 0 additions & 15 deletions packages/message-port-rpc/babel.jest.config.json

This file was deleted.

25 changes: 23 additions & 2 deletions packages/message-port-rpc/jest.config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
{
"testPathIgnorePatterns": ["/__tests__/__setup__/", "/lib/", "/node_modules/", "/__types__/", "\\.pnp\\.[^\\/]+$"],
"testPathIgnorePatterns": [
"/__tests__/__setup__/",
"/lib/",
"/node_modules/",
"/__types__/",
"\\.pnp\\.[^\\/]+$"
],
"transform": {
"/__tests__/types/": [
"<rootDir>/__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
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions packages/message-port-rpc/src/messagePortRPC.spec.ts
Original file line number Diff line number Diff line change
@@ -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<number>;
type MockFn = jest.Mock<Fn>;
Expand Down

0 comments on commit 3023174

Please sign in to comment.