1

I'm implementing e2e tests into an Angular project. It wasn't started with @angular-cli, so I'm configuring most of it manually.

What I'm trying to do now is to define a script in package.json to transpile only the specs in tests/ folder to tests/compiled.

I tried to follow this question: tsconfig.json - Only build ts files from folder. It recommends to use --rootDir to define the folder.

But if I use this: tsc --rootDir tests --outDir ./tests/compiled, it compiles files from other folders anyways (like ./src). Also, it returns a lot of TS6059 errors, complaining that rootDir should contain all source files.

An example: error TS6059: File 'C:/Users/Betalabs/Documents/Projetos/Engine-Frontend/src/vendor.browser.ts' is not under 'rootDir' 'tests'. 'rootDir' is expected to contain all source files.

The file hierarchy is this. Please note that the test specs (*.spec.ts) I want to transpile are in the tests/ folder.

(root) -- src/ -- tests/ -- compiled/ -- (transpiled test files, ".js") -- helpers/ -- (helper modules, ".ts") -- page-objects/ -- (page objects, ".ts") -- forms.spec.ts -- filters.spec.ts -- .gitignore -- .tern-project -- buildspec.yml -- conf.js -- package-lock.json -- package.json -- README.md -- tsconfig.json -- tsconfig.webpack.json -- tslint.json -- typedoc.json -- webpack.config.js 

This is my tsconfig.json:

{ "compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": true, "sourceMap": true, "noEmitHelpers": true, "importHelpers": true, "strictNullChecks": false, "baseUrl": "./src", "paths": { "@angular/*": ["node_modules/@angular/*"] }, "lib": [ "dom", "es6", "es2017.object" ], "typeRoots": [ "node_modules/@types" ], "types": [ "jasmine", "hammerjs", "node", "source-map", "uglify-js", "webpack" ] }, "exclude": [ "node_modules", "dist" ], "awesomeTypescriptLoaderOptions": { "forkChecker": true, "useWebpackText": true }, "compileOnSave": false, "buildOnSave": false, "atom": { "rewriteTsconfig": false } } 

I'm "solving" this by compiling all files anyways and removing the unnecessary ones manually. In other words: a complete mess :P

Could you help me with this?

1 Answer 1

1

In order to compile those files, you can use

"include": ["tests"] 

in your tsconfig


That being said, I think it'd be much more easier to convert the project to use ng cli :) Good luck

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I'm on mobile but I'll try this solution as soon as possible.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.