From 9dbca77edc15327bdac84cf8f750fdf7f8227595 Mon Sep 17 00:00:00 2001 From: "roman.vasilev" <> Date: Fri, 14 Jun 2019 16:44:41 +0400 Subject: [PATCH 1/7] ci: Removed github workflow files, fixed build --- .github/main.workflow | 46 ------------------------------------------- CHANGELOG.md | 3 +-- Taskfile | 7 ++----- 3 files changed, 3 insertions(+), 53 deletions(-) delete mode 100644 .github/main.workflow diff --git a/.github/main.workflow b/.github/main.workflow deleted file mode 100644 index 49cb97b..0000000 --- a/.github/main.workflow +++ /dev/null @@ -1,46 +0,0 @@ -workflow "Main" { - on = "push" - resolves = ["Publish"] -} - -action "Install" { - uses = "docker://node" - runs = "npm" - args = "install" -} - -action "Test" { - needs = "Install" - uses = "docker://node" - runs = "npm" - args = "test" -} - -action "Pre Build" { - needs = "Install" - uses = "docker://stedolan/jq" - runs = "sh" - args = "Taskfile prebuild" -} - -action "Build" { - needs = "Pre Build" - uses = "docker://node" - runs = "npm" - args = "run build" -} - -# Filter for master branch -action "Master" { - needs = ["Test", "Build"] - uses = "actions/bin/filter@master" - args = "branch master" -} - -action "Publish" { - needs = "Master" - uses = "docker://node" - runs = "npx" - args = "semantic-release" - secrets = ["NPM_TOKEN", "GITHUB_TOKEN"] -} diff --git a/CHANGELOG.md b/CHANGELOG.md index eeef4a8..d8269fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,5 +3,4 @@ ### Features -* First release ([1fc88b8](https://github.com/unlight/typescript-transform-unspec/commit/1fc88b8)) -* First release ([352d144](https://github.com/unlight/typescript-transform-unspec/commit/352d144)) +* First release diff --git a/Taskfile b/Taskfile index 2cd43d8..1a299a5 100644 --- a/Taskfile +++ b/Taskfile @@ -1,14 +1,11 @@ #!/bin/bash PATH="$PWD/node_modules/.bin":$PATH -prebuild() { +build() { rm -rf dist cp -rf src dist && /usr/bin/find dist -name '*.spec.ts' | xargs rm -f - cat tsconfig.json | jq 'del(.include, .compilerOptions.outDir)' > dist/tsconfig.json + cat tsconfig.json | jq 'del(.include, .compilerOptions.outDir)' | jq -r '.compilerOptions.plugins[0].transform = "./index.ts"' > dist/tsconfig.json cp README.md LICENSE package.json dist -} - -build() { cd dist rm example.ts ttsc -p . From 87b3f782a9db20d61830019738723b4ca362f899 Mon Sep 17 00:00:00 2001 From: "roman.vasilev" <> Date: Fri, 14 Jun 2019 16:58:53 +0400 Subject: [PATCH 2/7] chore: Updated package.json --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9a40706..4339c05 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "node": ">=8" }, "repository": { - "type": "git" + "type": "git", + "url": "https://github.com/unlight/typescript-transform-unspec.git" }, "scripts": { "test": "npm run eslint && npm run tscheck && npm run test:cov && npm run typecov", @@ -39,6 +40,7 @@ "setupwebpack": "npm i -D webpack webpack-cli webpack-dev-server html-webpack-plugin source-map-loader ts-loader html-loader swc-loader @swc/core", "commit": "git-cz" }, + "dependencies": {}, "peerDependencies": { "typescript": ">=2.9" }, From 17b4f39aad884e481bf9ebaa5bb2acbd8b21a134 Mon Sep 17 00:00:00 2001 From: "roman.vasilev" <> Date: Fri, 14 Jun 2019 17:08:29 +0400 Subject: [PATCH 3/7] build: More verbose output --- Taskfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Taskfile b/Taskfile index 1a299a5..51ae57f 100644 --- a/Taskfile +++ b/Taskfile @@ -2,15 +2,17 @@ PATH="$PWD/node_modules/.bin":$PATH build() { - rm -rf dist - cp -rf src dist && /usr/bin/find dist -name '*.spec.ts' | xargs rm -f + set -x + rm -rfv dist + cp -rfv src dist && /usr/bin/find dist -name '*.spec.ts' | xargs rm -rvf cat tsconfig.json | jq 'del(.include, .compilerOptions.outDir)' | jq -r '.compilerOptions.plugins[0].transform = "./index.ts"' > dist/tsconfig.json - cp README.md LICENSE package.json dist + cp -v README.md LICENSE package.json dist cd dist - rm example.ts + rm -rvf example.ts ttsc -p . - rm tsconfig.json + rm -rvf tsconfig.json cd .. + set +x } "$@" From a9ef19de99f685502bd9ef974789447c0f860431 Mon Sep 17 00:00:00 2001 From: "roman.vasilev" Date: Fri, 14 Jun 2019 21:08:59 +0400 Subject: [PATCH 4/7] test: More tests --- src/example.ts | 6 +++++- src/index.spec.ts | 25 ++++++++++++++++++++++--- src/index.ts | 43 ++++++++++++++++++++++++++++++++++++++++--- src/test.ts | 7 ------- tslint.json | 1 + tt_tsconfig.json | 15 --------------- 6 files changed, 68 insertions(+), 29 deletions(-) delete mode 100644 src/test.ts delete mode 100644 tt_tsconfig.json diff --git a/src/example.ts b/src/example.ts index 17dc6d9..653ba6d 100644 --- a/src/example.ts +++ b/src/example.ts @@ -6,6 +6,10 @@ it('hello world test', () => { expect(hello()).toBe('hello world'); }); +jest.mock('foo'); + describe('hello world test', () => { - jest.mock('fs'); + beforeAll(() => { + jest.mock('foo'); + }); }); diff --git a/src/index.spec.ts b/src/index.spec.ts index 2bc775e..a4b7313 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -21,10 +21,29 @@ function transform(sourceText: string) { it('smoke test', () => { expect(lib).toBeTruthy(); - expect(transform(';')).toEqual(';'); + expect(transform(';')).toBe(';'); }); it('should be removed it call expression', () => { - debugger; - expect(transform('it()')).toEqual(''); + expect(transform('it()')).toBe(''); + expect(transform('xit()')).toBe(''); + expect(transform('fit()')).toBe(''); +}); + +it('should be removed describe call expression', () => { + expect(transform('describe()')).toBe(''); + expect(transform('xdescribe()')).toBe(''); + expect(transform('fdescribe()')).toBe(''); +}); + +it('functions with modifiers', () => { + expect(transform('describe.only()')).toBe(''); + expect(transform('describe.skip()')).toBe(''); + expect(transform('describe.any()')).toBe(''); + expect(transform('test.only()')).toBe(''); + expect(transform('test.skip()')).toBe(''); + expect(transform('test.any()')).toBe(''); + expect(transform('it.only()')).toBe(''); + expect(transform('it.skip()')).toBe(''); + expect(transform('it.any()')).toBe(''); }); diff --git a/src/index.ts b/src/index.ts index 11e6c99..88a8233 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,10 +15,47 @@ function visitor(node: ts.Node): ts.Node | undefined { return node; } +// todo: delete only global +const testMethodList = [ + 'jasmine', + 'jest', + 'before', + 'after', + 'beforeAll', + 'beforeEach', + 'afterAll', + 'afterEach', + 'describe', + 'fdescribe', + 'xdescribe', + 'it', + 'fit', + 'xit', + 'test', + 'xtest', + 'spyOn', +]; + +function isTestExpressionText(text: string | ts.__String) { + return testMethodList.includes(String(text)); +} + function isSpecExpressionStatement(node: ts.Node) { - return (ts.isExpressionStatement(node) && ts.isCallExpression(node.expression) - && ts.isIdentifier(node.expression.expression) - && node.expression.expression.escapedText === 'it'); + if (ts.isExpressionStatement(node) && ts.isCallExpression(node.expression)) { + const callExpr = node.expression.expression; + if (ts.isIdentifier(callExpr) && isTestExpressionText(callExpr.escapedText)) { + console.log("callExpr", callExpr.flags); + return true; + } + if (ts.isPropertyAccessExpression(callExpr)) { + const propertyAccessExpr = callExpr.expression; + if (ts.isIdentifier(propertyAccessExpr) && isTestExpressionText(propertyAccessExpr.escapedText)) { + console.log("propertyAccessExpr", propertyAccessExpr.flags); + return true; + } + } + return false; + } } module.exports = typescriptTransformUnspec; diff --git a/src/test.ts b/src/test.ts deleted file mode 100644 index 614150d..0000000 --- a/src/test.ts +++ /dev/null @@ -1,7 +0,0 @@ -const a = { b: 1 }; -declare function safely(a: any): void; - -function abc() { - const c = safely(a.b); -} -console.log(abc.toString()); diff --git a/tslint.json b/tslint.json index 360ae7f..2680ac4 100644 --- a/tslint.json +++ b/tslint.json @@ -47,6 +47,7 @@ "no-reserved-keywords": false, "no-increment-decrement": false, "no-unnecessary-bind": false, + "newline-per-chained-call": false, ".": false } } diff --git a/tt_tsconfig.json b/tt_tsconfig.json deleted file mode 100644 index 75406cb..0000000 --- a/tt_tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "declaration": true, - "module": "commonjs", - "strict": true, - "outDir": "../dist", - "plugins": [ - { - "transform": "./transformers/transformer.ts" - } - ] - }, - "exclude": ["transformers/**/*"] -} From bc093721bdcb3c986bd4c2d921362fde79c955df Mon Sep 17 00:00:00 2001 From: "roman.vasilev" Date: Fri, 14 Jun 2019 21:20:39 +0400 Subject: [PATCH 5/7] fix: Fixed build --- package.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 4339c05..d2cb10d 100644 --- a/package.json +++ b/package.json @@ -45,22 +45,22 @@ "typescript": ">=2.9" }, "devDependencies": { - "@semantic-release/changelog": "^3.0.2", + "@semantic-release/changelog": "^3.0.4", "@semantic-release/commit-analyzer": "^7.0.0-beta.2", "@semantic-release/git": "^7.1.0-beta.3", - "@semantic-release/github": "^5.4.0-beta.1", + "@semantic-release/github": "^5.4.0", "@semantic-release/npm": "^5.2.0-beta.6", - "@semantic-release/release-notes-generator": "^7.1.7", - "@types/jest": "^24.0.13", - "@types/node": "^12.0.2", - "@typescript-eslint/eslint-plugin-tslint": "^1.9.0", - "@typescript-eslint/parser": "^1.9.0", + "@semantic-release/release-notes-generator": "^7.2.0", + "@types/jest": "^24.0.14", + "@types/node": "^12.0.8", + "@typescript-eslint/eslint-plugin-tslint": "^1.10.2", + "@typescript-eslint/parser": "^1.10.2", "eslint": "^5.16.0", "eslint-import-resolver-node": "^0.3.2", "eslint-plugin-import": "^2.17.3", "eslint-plugin-jest": "^22.6.4", "eslint-plugin-only-warn": "^1.0.1", - "eslint-plugin-unicorn": "^8.0.2", + "eslint-plugin-unicorn": "^9.1.0", "eslint-plugin-wix-editor": "^2.0.0", "jest": "^24.8.0", "npm-run-all": "^4.1.5", @@ -69,20 +69,20 @@ "remark-license": "^5.0.1", "remark-toc": "^5.1.1", "semantic-release": "^16.0.0-beta.19", - "simplytyped": "^3.1.0", + "simplytyped": "^3.2.0", "source-map-loader": "^0.2.4", "ts-jest": "^24.0.2", "ts-loader": "^6.0.2", "ts-node": "^8.2.0", - "tslint": "^5.16.0", + "tslint": "^5.17.0", "tslint-clean-code": "^0.2.9", "tslint-microsoft-contrib": "^6.2.0", "tslint-sonarts": "^1.9.0", "ttypescript": "^1.5.7", "type-coverage": "^2.0.2", - "typescript": "~3.4.5", + "typescript": "~3.5.2", "watchexec-bin": "^1.0.0", - "webpack": "^4.33.0", + "webpack": "^4.34.0", "webpack-cli": "^3.3.4" }, "config": { From e7afd372a91cf5176958be0a6ac37e14279ea5d9 Mon Sep 17 00:00:00 2001 From: "roman.vasilev" Date: Fri, 14 Jun 2019 21:31:45 +0400 Subject: [PATCH 6/7] fix: Removed debug code --- package.json | 9 +++++++-- src/example.ts | 4 +--- src/index.spec.ts | 8 +++----- src/index.ts | 11 +++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index d2cb10d..9e3e88b 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,16 @@ "name": "typescript-transform-unspec", "version": "0.0.0-dev", "license": "MIT", - "description": "Typescript transform plugin", + "description": "Typescript transform plugin removes spec definition from source file", "main": "index.js", "typings": "index.d.ts", "author": "2019", - "keywords": [], + "keywords": [ + "typescript-transformer", + "typescript-plugin", + "typescript-transform-plugin", + "typescript-compiler" + ], "engines": { "node": ">=8" }, diff --git a/src/example.ts b/src/example.ts index 653ba6d..ed72b81 100644 --- a/src/example.ts +++ b/src/example.ts @@ -6,10 +6,8 @@ it('hello world test', () => { expect(hello()).toBe('hello world'); }); -jest.mock('foo'); - describe('hello world test', () => { beforeAll(() => { - jest.mock('foo'); + jest.mock('inspector'); }); }); diff --git a/src/index.spec.ts b/src/index.spec.ts index a4b7313..9d58bc4 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -1,15 +1,13 @@ /* eslint-disable @typescript-eslint/tslint/config */ -import * as lib from './index'; +import transformPlugin from './index'; import * as ts from 'typescript'; -let transformPlugin: typeof lib.typescriptTransformUnspec = lib as any; - function transform(sourceText: string) { const program = ts.createProgram({ rootNames: [], options: {}, }); - const transformer = transformPlugin(program, {}); + const transformer = transformPlugin(program); const sourceFile = ts.createSourceFile('filename.tsx', sourceText, ts.ScriptTarget.ES5, true, ts.ScriptKind.TSX); let result: string | undefined; const writeCallback = (fileName: string, data: string) => { @@ -20,7 +18,7 @@ function transform(sourceText: string) { } it('smoke test', () => { - expect(lib).toBeTruthy(); + expect(transformPlugin).toBeTruthy(); expect(transform(';')).toBe(';'); }); diff --git a/src/index.ts b/src/index.ts index 88a8233..c781c41 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,15 @@ import * as ts from 'typescript'; -export function typescriptTransformUnspec(program: ts.Program, options?): ts.TransformerFactory { +export default function typescriptTransformUnspec(program: ts.Program): ts.TransformerFactory { // tslint:disable-line:no-default-export return (context) => (file) => visitNodeAndChildren(file, program, context); } function visitNodeAndChildren(node: ts.Node, program: ts.Program, context: ts.TransformationContext): ts.SourceFile { - return ts.visitEachChild(visitor(node), (childNode) => visitNodeAndChildren(childNode, program, context), context) as ts.SourceFile; + const visitor = (childNode) => visitNodeAndChildren(childNode, program, context); + return ts.visitEachChild(filterNode(node), visitor, context); } -function visitor(node: ts.Node): ts.Node | undefined { +function filterNode(node: T): T | undefined { if (isSpecExpressionStatement(node)) { return undefined; } @@ -44,18 +45,16 @@ function isSpecExpressionStatement(node: ts.Node) { if (ts.isExpressionStatement(node) && ts.isCallExpression(node.expression)) { const callExpr = node.expression.expression; if (ts.isIdentifier(callExpr) && isTestExpressionText(callExpr.escapedText)) { - console.log("callExpr", callExpr.flags); return true; } if (ts.isPropertyAccessExpression(callExpr)) { const propertyAccessExpr = callExpr.expression; if (ts.isIdentifier(propertyAccessExpr) && isTestExpressionText(propertyAccessExpr.escapedText)) { - console.log("propertyAccessExpr", propertyAccessExpr.flags); return true; } } - return false; } + return false; } module.exports = typescriptTransformUnspec; From 3831137185402a2724407bc8bf2ac3f267bb5f40 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 14 Jun 2019 17:51:18 +0000 Subject: [PATCH 7/7] chore(release): 1.0.1 [skip ci] ## [1.0.1](https://github.com/unlight/typescript-transform-unspec/compare/v1.0.0...v1.0.1) (2019-06-14) ### Bug Fixes * Fixed build ([bc09372](https://github.com/unlight/typescript-transform-unspec/commit/bc09372)) * Removed debug code ([e7afd37](https://github.com/unlight/typescript-transform-unspec/commit/e7afd37)) --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8269fc..e69b71e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## [1.0.1](https://github.com/unlight/typescript-transform-unspec/compare/v1.0.0...v1.0.1) (2019-06-14) + + +### Bug Fixes + +* Fixed build ([bc09372](https://github.com/unlight/typescript-transform-unspec/commit/bc09372)) +* Removed debug code ([e7afd37](https://github.com/unlight/typescript-transform-unspec/commit/e7afd37)) + # 1.0.0 (2019-06-14)