Reputation: 15525
I am re-implementing existing functionality with Typescript, and I would like to use Jasmine for testing. I had started using Jasmine with Javascript specs, but that feels wrong. Now I try to use Typescript specs (which feels right), but I am not able to find the right configuration to produce the javascript files at the correct locations.
I am using:
with the following structure:
/base_dir
/src
*.ts files
/src-spec
*.ts files (only specs)
/spec
*.js files (generated by typescript compiler I hope)
/lib/js
*.js files (generated by typescript compiler as well)
I have currently defined the following configuration for Grunt:
ts: {
libs : {
src: ["src/*.ts", "!node_modules/**"],
outDir: 'lib/js',
options: {
keepDirectoryHierarchy: false,
rootDir: "lib/js"
}
},
specs : {
src: ["src-spec/*.ts"],
outDir: ['spec'],
options: {
rootDir: "spec",
keepDirectoryHierarchy: false
}
}
But the resulting directory structure is the following:
/lib/js/*.js files // produced correctly
/spec/src/*.js // same content as /lib/js
/spec/src-spec/*.js // the corresponding spec file
And when I run Jasmine, the spec file in /spec/src-spec/
does not find the libraries located in /lib/js
and /spec/src
.
What is the recommended solution here for
Upvotes: 2
Views: 74
Reputation: 15525
The answer of @basarat gave me the right direction, here is the solution that fits my question above:
Change the structure to:
/src
*.ts (app files)
tests/*.ts (test files)
/lib/js
*.js (generated app files)
tests/*.js (generated test files)
jasmine.json (configuration for the changed paths)
jasmine.json
had to be changed to:
{
"spec_dir": "lib/js/tests"
...
}
Gruntfile.js
has to be changed to:
jasmine: {
exec: 'jasmine.cmd JASMINE_CONFIG_PATH=jasmine.json'
}
After that, all files are compiled as usual, go to the right place, and references from app files to others and spec files to app files are stable.
Upvotes: 1
Reputation: 275917
What is the recommended solution here
Personally I like a single tsconfig.json
for IDE integration. Everything inside src
(including tests) with outDir
to lib
. Finally simply .npmignore
lib/tests
.
The organization for src
and lib
is covered here : https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html
Upvotes: 2