Closed node-ex closed 1 year ago
There are 2 configs with custom names that are used when running Jest tests: jest.config.angular.ts and tsconfig.spec.ts.
Hello, since you are using a custom jest config file name, the docs section that you have referenced points to the article on how to override Wallaby auto-config to specify custom Jest config path:
module.exports = () => {
return {
testFramework: {
// the jest configuration file path
// (relative to project root)
configFile: './jest.config.angular.ts'
}
}
};
Please try the solution and let us know if it's working for you.
@ArtemGovorov Thank you for a suggestion, tried it out by creating wallaby.js
file and pointing Wallaby.js extension to it (VSCode -> Wallaby.js: Select Configuration), but it did not change the error message.
To be clear, I did see the mentioned section in the documentation and tried other configuration settings as well, but after multiple unsuccessful attempts decided to start from scratch, without it. Here is the config that I used before - I experimented with it by iteratively commenting/uncommenting some parts and seeing whether it will help, but without success:
testFramework: { configFile: './jest.config.angular.js', },
This should be enough, however it's referencing a .js
file, while you have originally mentioned that your Jest config is a .t
file jest.config.angular.ts
. Can you please check the discrepancy and try changing the extension in your config if the config file is .ts
file.
Can you please also share
jest.config.angular
config file,tsconfig.spec.ts
file in your original message, did you mean tsconfig.spec.json
or it's some other custom Jest config file?Sorry for the confusion regarding the filenames, I have provided incorrect extensions, here are the correct ones:
jest.config.angular.js
tsconfig.spec.json
New Wallaby diagnostics report, based on the setup with wallaby.js
config file:
You require ts-jest
in jest.config.angular.js
but it's not installed as a dependency in package.json
. Could you please provide us with a working sample project demonstrating the issue?
Yes, I will create a working sample project, perhaps will find the root cause in the process 😄
Here is a repository with a minimalistic working sample project: https://github.com/node-ex/angular-jest-wallaby-setup-sample-project
In this project Wallaby.js output still mentions that Jest is unable to parse test file, but this time it cannot handle type annotation, not the very first import
as in my original case.
I've provided information about the setup, all performed steps, and result in the README.md
.
Thanks for the sample repo.
Your project is using @angular-builders/jest@v15.0.0
which has a breaking change that Wallaby was not compatible with.
Please update to the latest version of Wallaby core, v1.0.1368
and delete your wallaby.js
configuration file, it should work for you.
You can also update your Wallaby configuration file to explicitly use jest and it should also work for you:
wallaby.js
module.exports = () => {
return {
autoDetect: ['jest'],
testFramework: {
configFile: './jest.config.js'
},
trace: true
}
};
Now it is indeed working as expected, thank you for the update!
Hello,
I have a small project that is based on Angular CLI + Jest setup (via Angular Jest Builder).
ng test
works, but Wallaby.js does not, even though, according to documentation, it should work with Automatic configuration.Here is the only test in the project:
It fails on the first
import
with an errorSyntaxError: Cannot use import statement outside a module
. It looks like*.spec.ts
files are not transpiled into the JS form that can be read by Jest.There are 2 configs with custom names that are used when running Jest tests:
jest.config.angular.ts
andtsconfig.spec.ts
.Could you, please, help me make this setup work with Wallaby.js?
Wallaby diagnostics report
Wallaby diagnostics report
``` { editorVersion: '1.74.2', pluginVersion: '1.0.348', editorType: 'VSCode', osVersion: 'linux 5.4.0-135-generic', nodeVersion: 'v16.17.0', coreVersion: '1.0.1365', checksum: 'NjU0ZjZhMmY2NWM4ZWExMGIyZDYyMmIxYWQxNDVmMDgsMTcwMDc4NDAwMDAwMCww', config: { diagnostics: { angular: { workspace: { '$schema': './node_modules/@angular/cli/lib/config/schema.json', version: 1, newProjectRoot: 'projects', projects: { 'angular-tic-tac-toe': { projectType: 'application', schematics: { '@schematics/angular:component': { style: 'scss' } }, root: '', sourceRoot: 'src', prefix: 'app', architect: { build: { builder: '@angular-builders/custom-webpack:browser', options: { customWebpackConfig: { path: './custom-webpack.config.ts' }, main: 'src/main.ts', index: 'src/index.html', tsConfig: 'tsconfig.app.json', outputPath: 'dist/angular-tic-tac-toe', polyfills: [ 'zone.js' ], assets: [ 'src/favicon.ico', 'src/assets', 'src/manifest.webmanifest' ], inlineStyleLanguage: 'scss', styles: [ 'node_modules/primeicons/primeicons.css', 'node_modules/primeng/resources/themes/lara-dark-blue/theme.css', 'node_modules/primeng/resources/primeng.min.css', 'src/styles.scss' ], scripts: [], serviceWorker: true, ngswConfigPath: 'ngsw-config.json' }, configurations: { production: { fileReplacements: [ { replace: 'src/environments/environment.ts', with: 'src/environments/environment.production.ts' } ], budgets: [ { type: 'initial', maximumWarning: '500kb', maximumError: '1mb' }, { type: 'anyComponentStyle', maximumWarning: '2kb', maximumError: '4kb' } ], outputHashing: 'all' }, development: { fileReplacements: [ { replace: 'src/environments/environment.ts', with: 'src/environments/environment.development.ts' } ], buildOptimizer: false, optimization: false, vendorChunk: true, extractLicenses: false, sourceMap: true, namedChunks: true } }, defaultConfiguration: 'production' }, serve: { builder: '@angular-builders/custom-webpack:dev-server', options: { browserTarget: 'angular-tic-tac-toe:build' }, configurations: { production: { browserTarget: 'angular-tic-tac-toe:build:production' }, development: { browserTarget: 'angular-tic-tac-toe:build:development' } }, defaultConfiguration: 'development' }, 'extract-i18n': { builder: '@angular-builders/custom-webpack:extract-i18n', options: { browserTarget: 'angular-tic-tac-toe:build' } }, lint: { builder: '@angular-eslint/builder:lint', options: { lintFilePatterns: [ 'src/**/*.ts', 'src/**/*.html' ] } }, deploy: { builder: '@angular/fire:deploy', options: { prerender: false, ssr: false, browserTarget: 'angular-tic-tac-toe:build:production', firebaseProject: 'angular-tic-tac-toe-eb2e5', firebaseHostingSite: 'angular-tic-tac-toe-eb2e5' } }, test: { builder: '@angular-builders/jest:run', options: { configPath: 'jest.config.angular.js', tsConfig: 'tsconfig.spec.json', assets: [ 'src/favicon.ico', 'src/assets' ], styles: [ 'src/styles.scss' ], scripts: [] } } } } }, cli: { schematicCollections: [ '@angular-eslint/schematics' ] } } }, jest: { config: { configs: [ { automock: false, cache: true, cacheDirectory: '/tmp/jest_rs', clearMocks: false, coveragePathIgnorePatterns: [ '/node_modules/' ], cwd: '