Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Typescript transform plugin removes spec definition from source file

License

NotificationsYou must be signed in to change notification settings

unlight/typescript-transform-unspec

Repository files navigation

Typescript transform plugin removes spec definition from source file.
Inspired byunassert.

Motivation

Imagine we havefunction.ts with single function. Usually we createfunction.spec.ts with tests.But what if we can keep tests in same file, and remove spec defenition for production.

Example

Before

exportfunctionhello(greet='world'){return`hello${greet}`;}it('hello world test',()=>{expect(hello()).toBe('hello world');});

After (it removed)

functionhello(greet){if(greet===void0){greet='world';}return"hello "+greet;}

Pros and Cons

+ All in one file
- Collecting coverage can be tricky

Installation

npm install --save-dev typescript-transform-unspec

Usage

webpack (with ts-loader or awesome-typescript-loader)

// webpack.config.jsconstunspecTransformer=require('typescript-transform-unspec');rules:[{test:/\.tsx?$/,loader:'ts-loader',// or 'awesome-typescript-loader'options:{getCustomTransformers:program=>({before:[unspecTransformer(program),]})}},]

TTypescript

// tsconfig.json{"compilerOptions": {"plugins": [            {"transform":"typescript-transform-unspec" },        ]    },}

Rollup (with rollup-plugin-typescript2)

// rollup.config.jsimporttypescriptfrom'rollup-plugin-typescript2';importunspecTransformerfrom'typescript-transform-unspec';plugins:[typescript({transformers:[service=>({before:[unspecTransformer(service.getProgram())],after:[],}),],}),]

Resources

About

Typescript transform plugin removes spec definition from source file

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp