Skip to content

Commit

Permalink
Bump scaffold (#37)
Browse files Browse the repository at this point in the history
Co-authored-by: @compulim <@compulim>
  • Loading branch information
compulim-workflow-bot[bot] authored Sep 25, 2023
1 parent 15e31a8 commit bdc36be
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.jest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
env:
es2021: true
es2022: true
jest: true
rules:
# Disable for convenience
Expand Down
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"
}
]
]
}
]
}
}
41 changes: 41 additions & 0 deletions packages/use-ref-from/__tests__/__setup__/typingTestTransformer.js
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 })})` };
}
};
14 changes: 0 additions & 14 deletions packages/use-ref-from/babel.jest.config.json

This file was deleted.

16 changes: 15 additions & 1 deletion packages/use-ref-from/jest.config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
{
"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-react",
"@babel/preset-typescript",
[
"@babel/preset-env",
{
"modules": "commonjs",
"targets": {
"node": "18"
}
}
]
],
"sourceMaps": true
}
]
}
Expand Down

0 comments on commit bdc36be

Please sign in to comment.