Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests (usually) do not attach to debugger unless the focus is on the file that is being tested - Inconsistent #249

Open
1 of 3 tasks
arketec opened this issue Oct 14, 2020 · 0 comments

Comments

@arketec
Copy link

arketec commented Oct 14, 2020

Description

So this is a sometimes repeatable issue, but not consistently repeatable. What is occurring here with some of my projects is I will create a unit test to test a piece of code like a data access agent or an API controller, and hit the "debug" button to attempt to step through the debugger. What happens (not always) is the debugger doesn't attach and skips past all breakpoints, unless the file of the function being tested is open and in view focus (ie: I open the file and stare at it until the debugger attaches). If the file is open but not in focus, the debugger will (often, but not always) skip any breakpoints in that file. If I have another file in focus later in the workflow, it will sometime break on that open file in focus instead of one before, and sometimes it will break in the open file not in focus. Its really inconsistent behavior that gets very annoying when unit testing and I often have to run a unit test 3 or 4 times before I find which part of the code is failing so I can open the file and watch it attach.

Steps to Reproduce

Create a project with a modular design and broken out by separation of concerns
Create unit tests that might span across several files/modules
set breakpoints inside the files
cause an error somewhere in code (after the first breakpoint is supposed be hit), but keep that file out of view focus
what the debugger detach and the unit test continue running in the background (you can see the output in sideBar-tests window)

Note: This does not always trigger the issue! Sometimes, following these exact steps will still break in the debugger, but usually it will detach and continue running

Expected Results

I expected breakpoints placed before any errors to break in the debugger. It does work sometimes, but very inconsistently

Actual Results

The debugger detaches and continues running in the background

Settings file

"mocha.coverage": {
"enable": false,
"decoration": true,
"runWithInterval": false,
"autoUpdateInterval": 20000,
"activeOnStart": true,
"runAfterTest": false,
"runCoverageAfterFileSave": false,
"reporters": []
},
"mocha.files.glob": "/test//.test.ts",
"mocha.requires": [
"ts-node/register"
],
"mocha.logVerbose": true,
"mocha.options": {
"timeout": "999999",
"files": "
.d.ts",
"exit": true,
"fullTrace": true
},

Versions

  • VScode: v1.50.0
  • Mocha SideBar: v0.22.2
  • Node Version: v12.4.0 (also tried v10.2.1 with the same issues)

OS version

  • Linux
  • Mac
  • Windows

Example for reproducing

it ('should create a new claim, scope, and client and the add the new scope to a client', async () => {
    const claim_name = 'test_client_claim_new'
    const scope_name = 'test_client_scope_new'
    const claim_agent = new ClaimsDataAgent()
    const scope_agent = new ScopesDataAgent()
    await scope_agent.create({name: scope_name} as IScopeDocument)
    const agent = new ClientDataAgent()
    const result = await agent.create({
        agency_id: 1,
        contact_id: 1,
        service_channel_id: 1,
        id: new_creds.id,
        secret: new_creds.secret,
        redirectUri: '',
        name: 'test'
    } as IClientDocument)
    const scope_result = await scope_agent.getByName(scope_name)
    await agent.addScope(result.id, scope_result)
    let client = await agent.getByClientId(result.id)
    expect(client.authorized_scopes).to.have.length.greaterThan(0)
    expect(client.authorized_scopes[0]).to.have.property('name', scope_name)
    expect(client.authorized_scopes[0]).to.have.property('claims')
    expect(client.authorized_scopes[0].claims).to.have.length.greaterThan(0)
    await claim_agent.deleteByName(claim_name)
    client = await agent.getByClientId(new_creds.id)
    expect(client.authorized_scopes).to.have.length.greaterThan(0)
    expect(client.authorized_scopes[0]).to.have.property('name', scope_name)
    expect(client.authorized_scopes[0]).to.have.property('claims')
    expect(client.authorized_scopes[0].claims).to.have.length(0)
    await scope_agent.deleteByName(scope_name)
    client = await agent.getByClientId(new_creds.id)
    expect(client.authorized_scopes).to.have.length(0)
})

All classes are simple mongo model interfaces with some functionality to add/remove scopes from the client and claims from scopes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant