Closed jagreehal closed 6 years ago
Unfortunately Stencil doesn't support source maps, so code coverage tools based like Wallaby or Istanbul can't work with it.
And even though test runs with no coverage are possible with Jest, the lack of source maps also breaks all error reports. For example, if you add a new line boom
at the end of your my-app.tsx
file and run npm test
, you'll see that the reported error stack lines are not correct.
Also, the lack of source maps support may be the first but not the only show stopper, because it looks like Stencil is using some heavily customized TypeScript compilation, so wallaby standard TypeScript compiler (or even a standard TypeScript compilation without wallaby), will not work, because looks Stencil compiler is collecting some metadata before the compilation and doing a few other things. So writing a custom wallaby Stencil compiler may be required.
If we are looking at rapid unit test development, have we considered mocking stencil itself?
jest.mock('@stencil/core', () => {
return {
Component: jest.fn(),
Element: jest.fn(),
State: jest.fn(),
}
});
Might not work for every situation, but it does help get out the gate.
As of Stencil 2.9, they will now be supporting sourcemaps. https://github.com/ionic-team/stencil/issues/219 https://stenciljs.com/docs/config#sourcemap
I suggest we reopen this issue and find a way to allow for StencilJs development with Wallaby
The stencil docs say that Stencil performs unit testing using jest
, which means that Wallaby should work for you if jest works from the command line.
It looks like stencil has a custom setup for running tests instead of configuring jest to work via the CLI, which means that you will first need to configure jest to run from the CLI.
We used the stencil starter project (which includes some tests) and added jest.config.js
to the root directory:
jest.config.js
module.exports = {
preset: '@stencil/core/testing',
};
After doing that, jest ran from the CLI, and Wallaby also ran the tests successfully (without any configuration).
We're not all that familiar with stencil. If there are other things that the stencil CLI does before starting jest, you may need to update the jest configuration to do the same so that jest runs from the CLI. Alternatively, you could run Wallaby/Jest with a Wallaby configuration file and perform some other setup/hosting/etc. tasks there.
If you run into trouble and need help, please raise a new issue.
This might be due to the fact that I'm using tsx and not jsx. But I cannot get it to run with Wallaby. But All of my tests work with the CLI.
./src/components/salt-icon/test/salt-icon.spec.tsx: 'Const declarations' require an initialization value. (11:14)
9 | describe('salt-icon', () => {
10 | fit('Should render a proper SVG with the appropriate attributes and no opaque path', async () => {
> 11 | const icon: IconName = 'twitter';
| ^
This might be due to the fact that I'm using tsx and not jsx. But I cannot get it to run with Wallaby. But All of my tests work with the CLI.
I am using the .tsx files and it worked fine for me after adding the config file. I have kept my dependencies as up2date as possible:
"devDependencies": {
"@babel/core": "7.15.8",
"@stencil/core": "2.9.0",
"@stencil/react-output-target": "0.1.0",
"@stencil/sass": "1.5.2",
"@types/jest": "26.0.24",
"@types/prettier": "2.4.1",
"@types/puppeteer": "5.4.4",
"babel-loader": "8.2.2",
"copy-webpack-plugin": "9.0.1",
"jest": "26.6.3",
"jest-cli": "26.6.3",
"mutation-observer": "1.0.3",
"prettier": "2.4.1",
"puppeteer": "10.4.0",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-is": "16.13.1",
"typescript": "4.4.3",
"webpack": "5.58.1",
"workbox-build": "6.3.0",
"write-file-webpack-plugin": "4.5.1"
}
Not all of these may be applicable to you.
@MrGrigri:
This might be due to the fact that I'm using tsx and not jsx. But I cannot get it to run with Wallaby. But All of my tests work with the CLI.
You will need to make sure that npx jest
runs from the CLI. If you use stencil
CLI to run your tests then there is no guarantee that Wallaby will work.
jest.config.js
module.exports = { preset: '@stencil/core/testing', };
Thank you for this, gotten me closer to final configuration. For others who got the error:
jasmine is not defined
You'll need to update your jest.config.js
file to this:
module.exports = {
preset: '@stencil/core/testing',
globals: {
jasmine: { getEnv: () => null }
}
}
Which is a bit weird (since StencilJS uses Jest under-the-hood), but nonetheless makes WallabyJS compatible.
@visma-zanas-stundys - I believe that your problem may be related to using an older version of Wallaby with a newer version of Jest. There were some breaking changes in Jest v28, and I believe it could break with jasmine is not defined
without our Wallaby fix.
Would you be able to provide your Wallaby Diagnostics report for us to confirm?
If your license has expired, you can try the latest version by requesting a trial license.
Sure ;)
I have wallaby working in my repo https://github.com/jagreehal/stencil-how-to-test-components
Issue description or question
See repo https://github.com/jagreehal/stencil-wallabyjs-example.
So running
works fine, but I can't get wallaby to work for Stencil (https://stenciljs.com).
When setting the module to be 'commonjs' I get the following error:
When using default tsconfig, I get the error:
Wallaby.js configuration file
Code editor or IDE name and version
Visual Studio Code v1.19.2
OS name and version
OSX - Sierra