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

o.before() within a o.spec still runs even when no tests are running #61

Open
gilbert opened this issue Jun 9, 2023 · 4 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@gilbert
Copy link
Contributor

gilbert commented Jun 9, 2023

const o = require('ospec')

o.spec('Example', () => {
  o.before(() => {
    console.log("RUNNING BEFORE")
  })

  o('test1', () => {
    o(true).equals(true)
  })
})

o.only('test2', () => {
  o(true).equals(true)
})

In this example, the console log runs even though no test in that spec is running (due to the .only on test2). In my own project this is causing extra debug statements to show up in the console even though they're not relevant to the test I'm focusing on.

@pygy pygy added the bug Something isn't working label Jun 15, 2023
@pygy pygy self-assigned this Jun 15, 2023
@pygy
Copy link
Member

pygy commented Jun 15, 2023

Hi @gilbert thanks for the report. This should be fixable, I'll look into a solution.

@jonahx
Copy link

jonahx commented Aug 13, 2023

I ran into this myself. Has there been any progress? Not familiar with ospec codebase, but I might be able to find time to look into this if you don't have time @pygy. Let me know if you have any ideas for the solution already.

@jonahx
Copy link

jonahx commented Aug 15, 2023

May be other considerations I am missing, but updating this line to the following seems to work:

only.length === 0 ||
	Object.values(spec.children).some(
		x => x instanceof Task && only.includes(x.fn)
	) ? spec.before : [],

Could use Set for performance but since the number of only is typically 1 or small, it shouldn't matter for most use cases.

@gilbert
Copy link
Contributor Author

gilbert commented Oct 27, 2023

Any chance we can get @jonahx's fix into a new release? 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants