Code Monkey home page Code Monkey logo

Comments (15)

jspaine avatar jspaine commented on June 2, 2024 1

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.

from pantry-for-good.

jspaine avatar jspaine commented on June 2, 2024

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

from pantry-for-good.

spotlesscoder avatar spotlesscoder commented on June 2, 2024

OK, thanks

from pantry-for-good.

spotlesscoder avatar spotlesscoder commented on June 2, 2024

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

from pantry-for-good.

spotlesscoder avatar spotlesscoder commented on June 2, 2024

Thank you very much for all the help you provide. It's a pleasure to work like this.

from pantry-for-good.

spotlesscoder avatar spotlesscoder commented on June 2, 2024

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.

from pantry-for-good.

jspaine avatar jspaine commented on June 2, 2024

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.

from pantry-for-good.

spotlesscoder avatar spotlesscoder commented on June 2, 2024

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: '[email protected]',
        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:

image

This window opened:

image

Now im not sure how to continue

from pantry-for-good.

spotlesscoder avatar spotlesscoder commented on June 2, 2024

@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.

from pantry-for-good.

kenjiO avatar kenjiO commented on June 2, 2024

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.

from pantry-for-good.

spotlesscoder avatar spotlesscoder commented on June 2, 2024

Thanks! I'll try it

from pantry-for-good.

kenjiO avatar kenjiO commented on June 2, 2024

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
    }
  }
}

from pantry-for-good.

spotlesscoder avatar spotlesscoder commented on June 2, 2024

Great, works for me, too!

from pantry-for-good.

spotlesscoder avatar spotlesscoder commented on June 2, 2024

Thanks!

from pantry-for-good.

spotlesscoder avatar spotlesscoder commented on June 2, 2024

@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

from pantry-for-good.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.