svi3c / jasmine-ts Goto Github PK
View Code? Open in Web Editor NEWExecutes jasmine tests with ts-node
License: MIT License
Executes jasmine tests with ts-node
License: MIT License
Cannot get the jasmine-spec-reporter to work. Followed the very simple instruction on the main page.
(1) installed jasmine-spec-reporter
, I tried version 6.0.0
and 7.0.0
package.json
...
"devDependencies": {
"@tsconfig/node14": "^1.0.1",
"@types/jasmine": "^3.8.2",
"@types/node": "^16.4.6",
"jasmine": "^3.8.0",
"jasmine-spec-reporter": "^7.0.0",
"jasmine-ts": "^0.4.0",
"karma-mocha-reporter": "^2.2.5",
"ts-node": "^10.2.0",
"typescript": "^4.3.5"
}
...
/spec/support/jasmine.json
{
"spec_dir": "tests",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": false,
"reporters": [
{
"name": "jasmine-spec-reporter#SpecReporter",
"options": {
"displayStacktrace": "all"
}
}
]
}
but results always look the same, with or without the jasmine-spec-reporter
declaration.
> jasmine-ts ./tests/**/*.spec.ts
Started
.
1 spec, 0 failures
Finished in 0.005 seconds
what am I missing ?
I would like to specify some of nodes command line arguments for jasmine-ts (in particular the -r for requiring extra files). Ts-node allows all node command line arguments as well as ts-node's own. Would be wonderful if jasmine-ts could do the same (i.e. allow jasmine arguments + ts-node arguments + node arguments).
I am trying to use a jasmine.json file for configuration like the one below:
Unfortunately, spec files are not picked up (only works if I specify them on the command line as in this npm's example). Also, not all helper files are loaded. I have both a "typings.ts" and a "config.ts" file in the helpers dir refered to by the jasmine.json file below but only the "config.ts" is picked up.
{
"spec_dir": "src/spec",
"spec_files": [
"**/*[sS]pec.ts"
],
"helpers": [
"support/*.ts"
],
"stopSpecOnExpectationFailure": false,
"random": false
}
ts-node offers the --inspect flag that allows debugging. Our project relies on that flag to use the debugger in VS Code. We're having some issues with our unit tests, but we can't find anyway to attach a debugger to jasmine-ts. Please add support for the --inspect flag that is built-in to ts-node so we can use a proper debugger.
With the following package.json
{
"name": "jasmine-ts-sample-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"provision": "typings install",
"test": "jasmine-ts '*.spec.ts'"
},
"author": "",
"license": "ISC",
"devDependencies": {
"jasmine-ts": "0.0.2"
}
}
either running the tests or calling node_modules/.bin/jasmine-ts init
fires the following error:
var initReporters = () => {
^
SyntaxError: Unexpected token )
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
It is a great extension of jasmine.
The last commit was ~1.5 years ago. There are a few opened PR that merge needed for me to move forward with this package in my projects.
I understand if the maintainer is busy, but please report it. I will fork this repo and release new versions under my npm org if I wouldn't get any response within 24 hours.
I am waiting for your response, thx
Using --project option correctly passes a project value to ts-node.
But then the same project value is passed as a spec name to jasmine.
argv entries consumed by ts-node and node CLI options should be removed from argv before processing commandOptions for jasmine.
I need to run one test file, but it cannot be passed as argument. After last upgrade this is forced to run the spec.ts files according to the jasmin.json configuration file.
What I'm trying to do:
./node_modules/.bin/jasmine-ts ./test/business/user.spec.ts
but it gives me:
No specs found
So, if I try to pass the config file:
./node_modules/.bin/jasmine-ts --config=jasmine.json ./test/business/user.spec.ts
where the jasmine.json content is:
{
"spec_dir": "test",
"spec_files": ["**/*spec.ts"],
"random": false,
"reporters": [
{
"name": "jasmine-spec-reporter#SpecReporter",
"options": {
"displayStacktrace": "all"
}
}
]
}
it runs all the spec.ts files inside the test/business folder.
Please add one file support if the configuration file is not passed to the jasmine-ts command.
Regards
I am loving this project, but I can't seem to get Jasmine helpers working. I've tried using TS and JS files for my helpers, I've tried specifying their location using the --helper
flag on the command line and also by editing jasmine.json, and I can't seem to get anything to work.
Could someone provide an example of working helper files using jasmine-ts? Something simple, just like a beforeEach
or beforeAll
writing to console.log
?
When running my tests I get the following error:
(function (exports, require, module, __filename, __dirname) { import * as tslib_1 from "tslib";
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
I'm in an Angular project and we don't want to use karma for a few reasons.
This is probably because the Angular tsconfig uses module: esnext
.
Should I create an extra tsconfig only for the specs with commonjs
?
Hi, I have my code running well with previous version of jasmine-ts, but if I update to 0.3.0 and run tests it says always "No specs found"
The line is: jasmine-ts ./server/tsconfig.json "./server/spec/**/*.spec.ts"
any tip? I guess can be anything with paths, how can I check full path where it is looking for spec files?
Thanks
I'm new to unit testing and wasn't successful setting up the proper conf to make it work. For some reason, probably something obvious that I can't see, when I run 'npm test', I get '... Started. No Spec found'.
So, ideally, a super simple working example would be provided for noobs like me. I understand this is some tedious extra work for an experimented dev, so just a suggestion, not a request.
$ TS_NODE_FILES=true NODE_PATH=./ JASMINE_CONFIG_PATH=./test/jasmine.unit.json nyc jasmine-ts "test/unit/**/*.spec.ts"
/****/workspace/node-consumer-login-proxy_PR-581/node_modules/jasmine-ts/node_modules/yargs/build/index.cjs:2804
if (shim$1.Parser.looksLikeNumber(arg) &&
^
TypeError: shim$1.Parser.looksLikeNumber is not a function
at Object.Yargs.self._parsePositionalNumbers (/****/workspace/node-consumer-login-proxy_PR-581/node_modules/jasmine-ts/node_modules/yargs/build/index.cjs:2804:31)
at Object.Yargs.self._postProcess (/****/workspace/node-consumer-login-proxy_PR-581/node_modules/jasmine-ts/node_modules/yargs/build/index.cjs:2787:25)
at Object.parseArgs [as _parseArgs] (/****/workspace/node-consumer-login-proxy_PR-581/node_modules/jasmine-ts/node_modules/yargs/build/index.cjs:2774:21)
at Object.get [as argv] (/****/workspace/node-consumer-login-proxy_PR-581/node_modules/jasmine-ts/node_modules/yargs/build/index.cjs:2651:25)
at Object.<anonymous> (/****/workspace/node-consumer-login-proxy_PR-581/node_modules/jasmine-ts/lib/index.js:103:5)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Module.replacementCompile (/****/workspace/node-consumer-login-proxy_PR-581/node_modules/nyc/node_modules/append-transform/index.js:58:13)
at module.exports (/****/workspace/node-consumer-login-proxy_PR-581/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
at Object.<anonymous> (/****/workspace/node-consumer-login-proxy_PR-581/node_modules/nyc/node_modules/append-transform/index.js:62:4)
at Module.load (internal/modules/cjs/loader.js:928:32)
jasmine-ts@^0.3.0:
version "0.3.3"
resolved "https://registry.yarnpkg.com/jasmine-ts/-/jasmine-ts-0.3.3.tgz#a26990b53379c94df706add15887593f40032974"
integrity sha512-ISBmhSe1imdT2V3u681YgIIlpnt68dhdu8l94JeWfL4sYE67bfoHj2Coc1k1ND3u+DxQcHMTn8nCZ7Pr3dV6TQ==
dependencies:
yargs "^16.2.0"
Please make jasmine as a peer dependency that the latest version can be used.
The v2.6 being used by jasmine-ts doesn't support async/await
I am starting jasmine-ts
with nyc
as described but it looks like I need to specify all nyc
options within the npm test script:
package.json
"coverage": "nyc -r lcov -e .ts -x \"*.test.ts\" jasmine-ts \"src/**/*.test.ts\"",
Is it also possible to use it in combination with a .nycrc
file? Because I would like to do the following:
package.json
"test": "nyc jasmine-ts"
.nycrc
{
"nyc": {
"cache": false,
"extension": [
".ts",
".tsx"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"*.test.ts"
],
"reporter": [
"html"
]
}
}
But when I do the later then I only get this output from nyc:
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
Done in 4.68s.
Hey!
Do you have any good idea how to combine jasmine-ts with istanbul for code coverage?
I already tried sth. like istanbul cover --include-all-sources jasmine-ts spec/**/*.spec.ts
.
Any help would be appreciated!
When I upgrade to Jasmine 4.0.1 I get the following error:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/command' is not defined by "exports" in C:\projects\myProject\service\node_modules\jasmine\package.json
at new NodeError (internal/errors.js:322:7)
at throwExportsNotFound (internal/modules/esm/resolve.js:322:9)
at packageExportsResolve (internal/modules/esm/resolve.js:545:3)
at resolveExports (internal/modules/cjs/loader.js:450:36)
at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (C:\projects\myProject\service\node_modules\@cspotcode\source-map-support\source-map-support.js:679:30)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
warning " > [email protected]" has incorrect peer dependency "ts-node@>=3.2.0 <8".
If jasmine-ts supports ts-node 8 (see #32), then the peer dependency field in package.json
should also be updated.
Hi,
I am a newbie in typescript and jasmine.
I have a problem, when I test my object outside the it function, the fields of my object are right. But inside my lambda function callback passed to the it function, my object is reset.
`
describe('add to cart from empty cart', () => {
it("1 == 1", () => expect(1).toBe(1));
// jasmine.clock().install();
service = new CartService( new DataService());
let prod = {id: 3, libelle: "Produit", price : 10, price_html : "10€"} as Product;
it(`start with cart who doesn't contains the product ${prod.id}`,
() => expect( ((<any>service).collector as Cart).containsKey(prod.id)).toBe(false) );
console.log("before addproduct", service["collector"]);
service.addProduct(prod);
console.log("after addproduct", service["collector"]);
it(`end with cart who does contains the product ${prod.id}`,
() => {
console.log("on anonymous function end with", service["collector"]);
expect( ((<any>service).collector as Cart).containsKey(prod.id)).toBe(true)
});
})
`
As you can see on the console printing, my object lost data inside the it callback : https://i.imgur.com/3d7wdc6.png
Can you help to understand why ? How to fix it ?
Please see the full file joined
ts it callback lost data.zip
I have some non-deterministic errors with jasmine-ts where it sometimes report one error, sometimes another that could be related to caching. For this reason, I would like to try to disable ts-node's caching. Unfortunately, ts_nodes's "--no-cache" option seem to be be supported unlike other ts-node options. Maybe it is a spelling error because TS_NODE_OPTIONS in the source mentions "--cache" instead which is not known to me. So maybe TS_NODE_OPTIONS in the code should be changed as below (unless the "-" sign in "no-cache" confuses the parser? ).
const TS_NODE_OPTIONS = [
"fast",
"lazy",
"no-cache",
"cacheDirectory",
"compiler",
"project",
"ignore",
"ignoreWarnings",
"disableWarnings",
"getFile",
"fileExists",
"compilerOptions",
];
Hi,
We have a project written in JavaScript. I writing unit test for it in TypeScript using jasmine-ts.
I got the basic test case working. But when I import javascript files to my TS test case, I am getting module not found error.
Error: Cannot find module 'utils/normalizePath'
here is my TypeScript spec code
import normalizePath from 'utils/normalizePath';
describe ('normalizePath', () => {
it('test 1', () => {
normalizePath('asa');
});
});
utils/normalizePath is JS file located in source folder. In jasmine.json, there is no way included source files.
Any help is appreciated.
We have a program written in TypeScript and I use jasmine-ts
to execute my tests (also TypeScript). Since we have multiple developers working on multiple operating systems, we put all of our configuration in jasmine.json
and use --config=jasmine.json
. All of our tests execute properly, and we see the basic output in the console window. However, our custom reporter (JUnitXmlReporter from jasmine-reporters
) isn't generating any files.
After looking through the jasmine-ts source code, we found that our config file wasn't being checked for reporters. If we specify the configuration file using JASMINE_CONFIG_PATH, the JUnit reporter produces the proper XML files. We'd like to use the --config option to avoid complications with environment variables on multiple operating systems. The config file will have the same relative path and name on all of our workstations, so a static definition in an npm script fits our needs perfectly.
Hi ...
I have been using jasmine-ts for a while and it looks nice, but I am not sure how to load polyfills like node-fetch.
It seems like a good idea to include the polyfill as a helpers and enable "allowJS" in tsconfig, but it still does not load the "fetch" function in the global scope as expected.
Is this an expected behavior, or is it some kind of bug ?
/BL
I just realized that this package uses its own version of Jasmine. This is a problem for multiple reasons:
Please switch Jasmine to a peer dependency and just lock the range to a major version so that consumers can use their own jasmine.
I've written a custom matcher for jasmine and have an interface definition which should extend the jasmine Matchers<T>
interface with my function like this:
declare namespace jasmine {
interface Matchers<T> {
toEqualInstruction(expected: IInstruction): boolean;
}
}
This is not picked up by jasmine-ts
and it tells me the method doesn't exist. If I edit the d.ts
of the jasmine directly within node_modules\@types\jasmine
then the method is picked up correctly.
Do I need to do something specific to get jasmine-ts
to pick this up? or should it work?
So that I can see the report in Jenkins for example.
This is what I currently have, no report files produced, what should I use to produce report files (preferably readable by Jenkins..)
"reporters": [
{
"name": "jasmine-spec-reporter#SpecReporter",
"options": {
"displayStacktrace": "all"
}
}
]
Thanks.
In the package.json the version of yargs is ^13.2.4 but when we download it for our library the version it's using is actually ^8.0.2
This may be related to the version of yargs in the yarn.lock being ^8.0.2
Also there is both a yarn.lock and a package-lock.json, you should only have one or the other.
The lower version of yargs depends on os-locale which depends on mem version 1.1.0 which has a security vulnerability. If the higher version of yargs is used then this vulnerability goes away.
Hi
It will fail just because "yargs" does not parse it correctly.
Hi,
I'm sorry that I'm not actively maintaining this repo for some time now.
The reason is that I'm currently working with jest and I have no time left time to work on this project.
So if anyone is interested in taking over this project, feel free to contact me.
npm i -D @ert78gb/jasmine-ts
https://github.com/ert78gb/jasmine-ts
https://www.npmjs.com/package/@ert78gb/jasmine-ts
Thank you, @ert78gb!
After setting up my typescript project for jasmine tests I noticed that my ci system fails to run the tests. It always shows this message:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist' is not defined by "exports" in /drone/src/node_modules/ts-node/package.json
--
at applyExports (internal/modules/cjs/loader.js:490:9)
at resolveExports (internal/modules/cjs/loader.js:506:23)
at Function.Module._findPath (internal/modules/cjs/loader.js:634:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:952:27)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/drone/src/node_modules/jasmine-ts/lib/index.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Module.replacementCompile (/drone/src/node_modules/append-transform/index.js:60:13) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
after looking at the indicated line in jasmine-ts and the structure of ts-node I changed the import in jasmine-ts' index.js
- const dist_1 = require("ts-node/dist");
+ const dist_1 = require("ts-node");
this fixed the issue and from my understanding it doesn't change the behaviour of that import.
If I npm install this package, it seems to pull a version that doesn't include a commit that fixes an issue with reading compilerOptions...
I'm curious if the latest build can be published to npm?
I'm using this tool for a project with several tsconfig files and I was wondering if there's going to be an option inserted to provide the path to tsconfig file before running the jasmine tests. I can run the tsconfig file I want by copying a tsconfig file into the same directory as the jasmine.json
file or by changing the value of the TS_NODE_PROJECT
environment variable.
It would be better for my work flow if I could just call the jasmine-ts
with a param like --tsconfig path/to/tsconfig.json
. Is this in the works?
Can't even use the init command...
jasmine-ts init
SyntaxError: Unexpected token } in JSON at position 5341
at JSON.parse ()
at parse (C:\Temp\Projects\otf-server\node_modules\tsconfig\src\tsconfig.ts:195:15)
at readFileSync (C:\Temp\Projects\otf-server\node_modules\tsconfig\src\tsconfig.ts:181:10)
at Object.loadSync (C:\Temp\Projects\otf-server\node_modules\tsconfig\src\tsconfig.ts:151:18)
at readConfig (C:\Temp\Projects\otf-server\node_modules\ts-node\src\index.ts:425:18)
at Object.register (C:\Temp\Projects\otf-server\node_modules\ts-node\src\index.ts:189:18)
at Object. (C:\Temp\Projects\otf-server\node_modules\jasmine-ts\src\index.ts:23:1)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] init: jasmine-ts init
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] init script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
shouldn't it be helpers instead of helper?
with typescript 2.4.1 there was a breaking change to ts-node. ts-node now fails to find any @types navigation files
microsoft/TypeScript#16772 (comment)
this is fixed in ts-node v3.1.0
I'm not sure how feasible this is but I know serverless-webpack made webpack a peer dependency, making it so the user can use an arbitrary version of webpack with serverless-webpack. Can we do something similar with jasmine-ts?
I've got a project using jasmine-ts to run unit tests for me. We've configured our jasmine.json file to set "random" to "true" so tests are run with a random seed. This can help find unit test errors when bad assumptions are made.
However, when we get a failing test, I can't find a way to get that seed to be used by Jasmine again. I've attempted setting the seed property in the jasmine.json file; I've tried using a command line parameter; both are ignored. I've resorted to modifying jasmine's js code to use a static seed to run tests, but that seems less than ideal.
I'm not sure if anyone's actively looking at this or not, but thought I'd post the issue in case someone has ideas on how to get the seed passed through.
Steps:
Unknown options: --project
Usage: jasmine [command] [options] [files]
Because the last line of code which executes jasmine sends process.argv.slice(2), all of the arguments that ts-node knows which jasmine does not know get passed on.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.