-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15e31a8
commit bdc36be
Showing
5 changed files
with
80 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
41
packages/use-ref-from/__tests__/__setup__/typingTestTransformer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 })})` }; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters