GithubHelp home page GithubHelp logo

smolijar / intspector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from paulkoerbitz/resolve-types

5.0 5.0 0.0 396 KB

Inspect your TS types as strings and integrate type testing into your favorite testing framework!

License: MIT License

TypeScript 97.68% JavaScript 2.32%
detect inspect resolve string types typescript unit

intspector's People

Contributors

paulkoerbitz avatar smolijar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

intspector's Issues

host.readDirectory error while using inspectWithPreamble

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 ๐Ÿ™

Cannot import from local file

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.