I’m trying to set up jasmine-browser-runner for a TypeScript project.
My jasmine-config.mjs looks like this:
export default {
srcDir: 'src',
srcFiles: [],
specDir: 'src',
specFiles: [ './**/*Spec.ts' ],
helpers: ['jasmine-ts-node-register.js'],
enableTopLevelAwait: false,
env: {
stopSpecOnExpectationFailure: false,
stopOnSpecFailure: false,
random: true,
},
listenAddress: 'localhost',
hostname: 'localhost',
browser: { name: 'chrome' },
};
The helper jasmine-ts-node-register.js looks like this:
require('ts-node').register();
It is supposed to register ts-node, but it does not work, because require cannot be used in a browser. Running the tests with
npx jasmine-browser-runner runSpecs --config=./jasmine-config.mjs
fails with the error “No specs found”. But this is misleading, as specs are indeed found (I verified this by debugging jasmine-browser-runner), but none of them are actually called, because the helper above is called first, which aborts the tests. I changed a line in my local copy of jasmine-browser-runner that prevents Chrome from closing, and it reveals that, as expected, the require statement fails.
So, how can I set this up so that it actually works?
I could probably compile TypeScript files before calling jasmine-browser-runner, but I was hoping that I could set it up like to “watch” my files, which helps a lot when writing tests. Can I combine jasmine-browser-runner with webpack?