Closed spotlesscoder closed 6 years ago
There are some issues with the tests lately, I'm not sure what the problem is. You can run in watch mode with npm run test:server
or npm run test:client
OK, thanks
How can I debug into the tests? I really want to find out the source of the problem because I can't even commit with the failing tests and I don't want to change all the commit hook stuff
You can do npm run test:server:once -- --inspect
after putting debugger
in the test you want to break on, then open chrome://inspect.
You can also just commit or push with --no-verify
to skip running the tests.
Thank you very much for all the help you provide. It's a pleasure to work like this.
I did not succeed doing it. By "putting the debugger in the test" do you mean setting the breakpoint? I don't know how chrome would be able to read the breakpoints I set in vs code.
Thanks! I mean the debugger statement (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger), sorry I thought it might not have been that clear too.
It's also not great because you have to refresh chrome i think every time you re-run the tests, but I'm not sure there's a better way.
But I think removing the :once
would be correct, right? Otherwise, I don't see anything appearing in chrome://inspect
But even with the test running continuously, it didn't work.
I inserted the debugger like that (in server/tests/user.spec.js):
it('admins can set other users as admins', async function(){
const user = await User.create({
firstName: 'first',
lastName: 'last',
email: '123@example.com',
roles: [],
provider: 'local',
password: '12345678'
})
const adminUser = createTestUser('admin', ADMIN_ROLE)
const adminSession = await createUserSession(adminUser)
const adminReq = supertest.agent(adminSession.app)
debugger;
await adminReq.put(`/api/admin/users/${user._id}`)
.send({ isAdmin: true })
.expect(200)
const updatedUser = await User.findById(user._id).lean()
expect(updatedUser).to.have.property('roles')
expect(updatedUser.roles).to.include(ADMIN_ROLE)
})
Then I ran npm run test:server -- --inspect
Then, in chrome://inspect, I clicked "inspect" in the red marked area:
This window opened:
Now im not sure how to continue
@jspaine: I don't wanna rush you but want to make sure you have seen I'm still having trouble ;) It's totally fine if you don't have time at the moment ... it's not super urgent but would be great to know.
I am able to debug the server tests directly in VScode with this configuration in my .vscode/launch.json file.
{
"name": "Debug Server Tests",
"type": "node",
"request": "launch",
"protocol": "inspector",
"cwd": "${workspaceRoot}",
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": [
"--no-timeouts",
"--color",
"--require",
"babel-register",
"--require",
"server/entry.test.js",
"./server/tests/**/*.spec.js"
],
"smartStep": true,
"skipFiles": [
"node_modules/**/*.js",
"<node_internals>/**/*.js"
],
"env": {
"NODE_ENV": "test"
}
}
There is a problem where the breakpoints get moved to the last line of the file when I launch the tests. So I have to re-add the breakpoints while the test is running each time I debug the tests. There may be a setting with sourcemaps that could fix this.
Thanks! I'll try it
I got the breakpoints working by adding "sourceMaps": true
in the .vscode/launch.json configuration. Then I changed the .babelrc file to look like
"presets" : [
"flow"
],
"plugins": [
"transform-es2015-modules-commonjs",
"transform-async-to-generator",
"transform-object-rest-spread"
],
"env": {
"test": {
"plugins": ["istanbul", "babel-plugin-rewire"],
"sourceMaps": true,
"retainLines": true
}
}
}
Great, works for me, too!
Thanks!
@jspaine : I think the error is a mongodb related one. Maybe switching to the library referred here will help: https://github.com/chevex-archived/mongoose-auto-increment/issues/74
When I run the command
npm run test
on the staging branch, I get the following error:Is this ok or did I miss something the needs to be set up for the tests?
Another question: Is it possible to compile run the tests automatically when a piece of source code is changed?