-
-
Notifications
You must be signed in to change notification settings - Fork 305
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
'there can only be one only test' conflicts with 'before' test #463
Comments
Instead of using const setup = async () => {
await app.launch();
await browser.open();
});
test('route: hello world', async t => {
await setup();
await browser.goTo(APP.URL);
const pageContent = await browser.getPageContent();
t.equal(pageContent, 'hello world');
t.end();
}) |
yes that would work but I don't like it for 2 reasons.
|
Considering that there's not an official "before" feature in tape, I'm not sure how to handle it. Certainly, though, you could make the setup function memoized - so that it's safe to call it multiple times. |
I've actually solved my problem using this const test = require('tape')
const tests = []
const group = (description, test) => {
tests.push({description, test})
return group
}
group.run = (...args) => {
if (args.length) {
group(...args)
}
test.only('grouped tests', async t => {
const endTest = t.end
t.end = () => {}
for (const _test of tests) {
t.comment(_test.description)
await _test.test(t)
}
endTest()
})
}
test.group = group then in your test file const test = require('tape')
require('test/group')
test.group('some test', t => {})
test('some test', t => {})
test.group('some test', t => {})
test('some test', t => {})
test.group.run('some test', t => {})
test('some test', t => {})
test('some test', t => {}) It's not pretty but it's already saving me some time. Would be cool if there was a way to not have to call "run" on the last test |
I suppose you could do something gnarly like listen for the process exiting, and start the tests then. |
Do you know how? I tried this but it doesn't register the const test = require('tape')
const tests = []
let ran
const group = (description, test) => {
tests.push({description, test})
return group
}
group.run = (...args) => {
if (ran) {
return
}
ran = true
if (args.length) {
group(...args)
}
test.only('grouped tests', async t => {
const endTest = t.end
t.end = () => {}
for (const _test of tests) {
t.comment(_test.description)
await _test.test(t)
}
endTest()
})
}
test.group = group
const run = () => {
group.run()
}
process.on('beforeExit', run)
test('test one', t => {
t.pass()
t.end()
})
test.group('test two', t => {
t.pass()
t.end()
})
test('test three', t => {
t.pass()
t.end()
}) |
I'm not really sure as I haven't thought this through. Personally, even in test frameworks that have a |
I do the same for databases because they open pretty quick and you need a clean slate. But right now I'm testing an express app and need to open the browser, which takes too long, and need to launch the express app, which even if it's quick, it's tons of useless code repetition. My tests are small and I have many of them. it would make 5-10% of the entire file useless code repetition. |
I'm looking for a solution to a problem I'm having. Sometimes I need to isolate a test for a short period of time, but almost all my tests have setups like below. Commenting out all the other tests is really annoying, plus it stills runs the tests in my other files, so I need to comment all AND use a different glob pattern AND relaunch nodemon.
I'd be open to pretty much any solution, even if it involves modifying my tape node_modules since I only need this while i'm coding to improve productivity, it doesn't need to stay in the code permanently.
The text was updated successfully, but these errors were encountered: