Im try to test unit in Nestjs
But its showing error
Test suite failed to run
Cannot find module '#nestjs/core/inspector/graph-inspector' from '../node_modules/#nestjs/testing/testing-module.builder.js'
Require stack:
/Volumes/My Files/IdeaProjects/ChecklistApp/server/node_modules/#nestjs/testing/testing-module.builder.js
/Volumes/My Files/IdeaProjects/ChecklistApp/server/node_modules/#nestjs/testing/test.js
/Volumes/My Files/IdeaProjects/ChecklistApp/server/node_modules/#nestjs/testing/index.js
task/task.spec.ts
I have same problem with you, and i solved it. This problem is occurred because "#nestjs/core/inspector/graph-inspector" is missing but still referenced in "../node_modules/#nestjs/testing/testing-module.builder.js".
To solve this problem do following command:
npm i #nestjs/core && npm i #nestjs/testing
Note: above command will update the version of #nestjs/core and #nestjs/testing package to the latest version.
Related
I using mocha to do unit testing to my vuetify project
I had install it. So I run npm run test:unit, there exist error like this :
npm ERR! Failed at the test-vuetify#0.1.0 test:unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
The full error like this :
How can I solve this error?
Note :
When I first installed vuetify and tried unit testing, it worked. No error
After I edited some parts and ran the unit test, the above error appeared
How do I resolve this error?
Update :
I have updated the version of vuetify. Is that what caused this error?
I am confused to solve this error. Because all errors are located in the node-modules folder. Not in the component that I made
I have got that problem often . I want to share what I do in that situation . I run npm update on project folder then I rerun test command again . If it is solve , done . If not I delete all node_modules folder and run npm install and rerun test command . Then my problem gone . Hope you problem can solve too ..
Just a quick disclaimer, I cannot reproduce this on another project, which is why I'm here instead of making an issue on the Github.
Issue
So a quick demo project I made to show a co-worker how to use the Vue test utils, went off the wagon. It doesn't get picked up in the transform part of the jest.config.js.
I made the project with the Vue CLI, using vue create demo-project choosing ESlint and Babel, then running vue add #vue/cli-plugin-unit-jest. Everything went fine, I committed, ran the test command and everything went fine.
So we started testing snapshots, and everything was fine. Next day, come back to the project to keep going, and this is the error I get.
> vue-jest#0.1.0 test:unit .../demo-projects/vue-jest
> vue-cli-service test:unit
FAIL tests/unit/example.spec.js
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
.../demo-projects/vue-jest/tests/unit/example.spec.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { shallowMount } from '#vue/test-utils';
^
SyntaxError: Unexpected token {
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.163s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
Just running the normal npm run test:unit results in the example.spec.js that comes with the test utils is not babel'ed, and fails in the Node test environment.
Attempted Solutions
Did not work
Deleting node_modules and reinstalling
Deleting package-lock.json, in addition to the above step ( separately done )
Reverting back to the commit when it was working
Checking out to a different branch, deleting all the files that vue add #vue/cli-plugin-unit-jest added, then running the command again to re-create all the files
jest.config.js
tests/ - and all it's files
Worked
Pretty clear what's happening, so in the jest.config.js file, I added the .js file under the transform field.
transform: {
'^.+\\.vue$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
'^.+\\.(js|jsx)?$': 'babel-jest' // added .js
},
This solution solves the problem, and properly transforms the example.spec.js
Attempted Recreation
I tried to see if this was a bug by creating another project, running the same steps and it worked just fine. I even copied and pasted all the files from the broken one to the new one, looking for differences in git. It was exactly the same. Which is why I thought it might be node_modules, but it still didn't work.
Uhh
Hopefully this isn't a waste of time for anyone reading since it's not truly a problem. I mainly wanted to have it for anyone who might have the same issue to see that adding the .js extension would solve the problem without having to start over, but also curious if anyone has insight on why this might be happening?
I am new to unit testing (and would really like to learn). I tried pulling down this repository (https://github.com/serbanghita/Mobile-Detect) and have been trying to run their unit tests they already have set up. I have it to the point where phpunit is running but when I run
phpunit tests
from the root directory I get:
Tests: 1411, Assertions: 0, Errors: 1411
I have tried running
phpunit --configuration tests/phpunit.xml
but then I get the error:
Class "JohnKary\PHPUnit\Listener\SpeedTrapListener" does not exist
They have something in their documentation about running:
php phpunit.phar -c tests/phpunit.xml
but I get the error
Could not open input file: phpunit.phar
which is because of the way I have phpunit set up I'm sure...
Any suggestions on how to further trouble shoot this?
It appears you have configured https://github.com/johnkary/phpunit-speedtrap to be used as a test listener in your phpunit.xml but have not (properly) installed this extension.
And if your PHP cannot find phpunit.phar then you are either not pointing it to the correct path or you have not downloaded / installed the PHPUnit PHAR, maybe because you chose to install PHPUnit via Composer. In that case the correct path would be vendor/bin/phpunit, of course.
Trying to run my karma test through grunt but getting an error:
Error: [$injector:modulerr] Failed to instantiate module ngMock due to:
Error: [$injector:unpr] Unknown provider: $$asyncCallbackProvider
I removed 'ngAnimate' but does not resolve it. How can I run the grunt karma test without this error?
I had the same problem just now, and fixed it by making sure the version of my angular-mock dependancy was the same as that angular.
You can do this in your bower.json file (change "angular-mocks": "~1.3.0" to "angular-mocks": "^1.3.0" or a specific version).
While I have no doubt that 3sdmx's answer would work, I just ran an NPM update and that worked. Thought I should mention that so that people aren't maintaining their .json files so closely.
You should add all the angular dependencies that you used in your project to your karma.conf.js file.
It seems like you need to add ngMock to your karma file, like the example below :
files: [
'*/**/angula-ngMock.js'
],
I have successfully converted two projects from grails 2.2.4 to 2.4.3. I can run the tests, and run-app both from the grails command line, and within ggts.
Then, I converted it to a maven project, by using create-pom to get an initial pom.xml file. After getting the dependencies right, I can again run the tests and the app from the command line and ggts. But I am getting errors on my unit tests (not spock tests) using 'mvn test'.
The errors look like this:
java.lang.NullPointerException
at grails.test.runtime.GrailsApplicationTestPlugin.createParentContext(GrailsApplicationTestPlugin.groovy:143)
at grails.test.runtime.GrailsApplicationTestPlugin.initGrailsApplication(GrailsApplicationTestPlugin.groovy:96)
at grails.test.runtime.GrailsApplicationTestPlugin.onTestEvent(GrailsApplicationTestPlugin.groovy:327)
at grails.test.runtime.TestRuntime.deliverEvent(TestRuntime.groovy:295)
It feels like some kind of setup , or dependency issue.