smolijar / intspector Goto Github PK
View Code? Open in Web Editor NEWThis project forked from paulkoerbitz/resolve-types
Inspect your TS types as strings and integrate type testing into your favorite testing framework!
License: MIT License
This project forked from paulkoerbitz/resolve-types
Inspect your TS types as strings and integrate type testing into your favorite testing framework!
License: MIT License
I wanted to use this wonderful tool while updating tests on cosmas but I encountered a rather annoying error while using inspectWithPreamble
function.
Code:
console.log(inspectWithPreamble(`
import loggerFactory from 'cosmas';
const logger = loggerFactory('a');`)('typeof logger'));
And after running jest
tests, the error is following:
TypeError: host.readDirectory is not a function
17 | console.log(inspectWithPreamble(`
18 | import loggerFactory from '..';
> 19 | const logger = loggerFactory('a');`)('typeof logger'));
| ^
20 | expect(logger).toBeDefined();
21 | });
22 |
at getFileNamesFromConfigSpecs (node_modules/typescript/lib/typescript.js:26140:40)
at matchFileNames (node_modules/typescript/lib/typescript.js:26060:16)
at getFileNames (node_modules/typescript/lib/typescript.js:25628:26)
at parseJsonConfigFileContentWorker (node_modules/typescript/lib/typescript.js:25561:18)
at Object.parseJsonConfigFileContent (node_modules/typescript/lib/typescript.js:25510:16)
at convertConfigToCompilerOptions (node_modules/intspector/src/lib/options.ts:14:11)
at Object.<anonymous>.exports.setOptions (node_modules/intspector/src/lib/options.ts:57:26)
at Object.<anonymous>.exports.getOptions (node_modules/intspector/src/lib/options.ts:73:9)
at Object.<anonymous>.exports.createInlineProgram (node_modules/intspector/src/lib/program.ts:32:21)
at node_modules/intspector/src/lib/inspect.ts:34:11
at Object.<anonymous> (src/tests/create.test.ts:19:41)
Versions used:
intspector: 1.0.1
typescript: 3.5.3
jest: 24.1.0
Thanks for help
Hi, I have an error while trying to import type from local file.
Code
describe("Message", () => {
it("should not be ducktyped from empty object", () => {
const myInspect = inspectWithPreamble(`
import { Message } from "./Message";
const m: Message = {};
`);
try {
myInspect({
foo: "typeof m",
});
} catch (err) {
expect(err[0].messageText).toBe(
"Error message here"
);
}
});
});
This results with error message Cannot find module './Message'.
When I'm importing module from node_modules
it does not complain.
My source code is in src
folder.
Here's my tsconfig:
{
"compilerOptions": {
"esModuleInterop": true,
"experimentalDecorators": true,
"declaration": true,
"module": "esnext",
"moduleResolution": "node",
"noUnusedLocals": true,
"outDir": "./dist",
"rootDir": "./src",
"sourceMap": true,
"strict": true,
"target": "esnext",
"types": [
"jest"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
I tried all possible option I can think of, including tsconfig option from this repo, by setting them via setOptions
like this:
let opts = getOptions();
opts = setOptions({
...opts,
target: ts.ScriptTarget.ES5,
lib: ["es2017"],
noUnusedLocals: false,
module: ts.ModuleKind.CommonJS,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
});
I'm running tests with jest.
Is there anything I need to do/set to be able to import local files?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.