Comments (9)
It seems easy to add an option to pta to turn the Promise.all to a chained await.
await Promise.all(
files.map((file) => {
const filePath = resolve(process.cwd(), file);
return import(pathToFileURL(filePath));
})
);
for (const file of files) {
const filePath = resolve(process.cwd(), file);
await import(pathToFileURL(filePath));
}
Update: I realised this could not work because all tests in every single file are asynchronously executed.
from zora.
The other option is to add some env support in zora itself, something like ZORA_SERIAL=true
.
That's probably a better option than changing pta. Because the env can make sure all test()
calls are in serial. The pta change only ensures serialisation between files.
from zora.
HI,
The other option is to add some env support in zora itself, something like ZORA_SERIAL=true.
That's probably a better option than changing pta. Because the env can make sure all test() calls are in serial. The pta change only ensures serialisation between files.
That would be quite challenging with the current design and probably not something that I want. And by the way, if you run all the tests serially it won't make things faster than AvA/tape.
I am not sure to see why you'd need to run the tests serially though? are you restoring the fs at some point ? could you share some code please ?
If you need to setup the mock before you run the test you can have a setup file:
const mock = require('mock-fs');
mock({
'path/to/fake/dir': {
'some-file.txt': 'file content here',
'empty-dir': {/** empty directory */}
},
'path/to/some.png': Buffer.from([8, 6, 7, 5, 3, 0, 9]),
'some/other/path': {/** another empty directory */}
});
and then run node with a require hook: node -r test/setup.js node_modules/.bin/pta
.
If you really want to run multiple files serially in isolated environments you can spawn multiple processes with either a basic test runner or a simple bash command (with some caveats on the reporting I assume)
for f in test/*.spec.js; do pta $f; done
Or write your test files in some way they accept the assert
object and control yourself how the files get loaded within an entry point:
// some.spec.js
export default (t) => {
t.ok(true)
}
and entrypoint (or you can build a basic test-runner at this point: pta is only few lines of code if you need inspiration)
// test/index.js
import {test} from 'zora'
// this is a dummy test whose only purpose is to load the test suites and make them run serially
test(`my serial test`, async t => {
for (const f of files) { // files coming from shell args, config, env var (up to you)
const { deafult: suite } = await import(f); // or require depending on your project
await suite(t); // the await make sure the test suites run serially
}
})
Hope this gives you some idea to proceed. Again, the easier would be to share with me a reproduction of your current test setup
from zora.
Every test (test()
) has it's own mocked set of files, uses mockfs.restore()
to clean up at end of every test. It's not a global mock for all tests.
Since mock-fs stubs fs calls, it would not work well when two different mock in two tests (from two test.js files in my case) running in parallel by zora.
Within one test file, I can use await to queue the tests, but currently no solution across files.
from zora.
I found out I can use top level await (no commonjs), plus the suggested change in pta to queue up all tests.
pta is using import()
which works well with both commonjs and esm test files.
from zora.
I think the suggested change in pta could simply replace the current Promise.all
without introducing an option.
for (const file of files) {
const filePath = resolve(process.cwd(), file);
await import(pathToFileURL(filePath));
}
It would not cause noticeable performance lost for test files not using any top level await. I tested with another project (no use of mock-fs), there is no noticeable time change (all around 670ms to 680ms for full unit tests in 34 files).
With the change, the disk IO is definitely queued. But I doubt Nodejs parses all read-in files from Promise.all
with more than one process/thread.
With this change, global queued tests across files are possible.
from zora.
oh you mean if you write your test file as so:
// test.js
import {test} from 'zora';
await test('foo', fn); // with top level await
and we change pta with the suggested changes you gain the ability to run your tests in serie ?
Sounds good 👍
from zora.
❤️
from zora.
Latest pta works really well! Has to use --module-loader es
to load my tests. That also means I cannot mix cjs and es test files in pta, that's understandable.
Wrong module-loader only messes up the reporter, because of different zora instances (one loaded by pta to hold and report, another one in real tests).
from zora.
Related Issues (20)
- Difference to Tape / AVA? HOT 1
- Add examples for Svelte, Vue and React HOT 1
- Structured comparison HOT 6
- Switching between character/line diff? HOT 1
- Assert type problems: can't extend assertion types in TypeScript
- Improve diff reporter HOT 6
- Bad type-declaration for `throws` HOT 1
- Pipe error handling (write EPIPE) HOT 2
- Inconsistent behaviour of tap reporters HOT 2
- Empty test.ts file in the node-ts example HOT 1
- build npm package HOT 3
- Zora + pta doesn't work with top level dynamic imports HOT 5
- Discussion: enable mix of cjs and es test code. HOT 5
- Example of cleaner ts-node setup with pta + TypeScript
- Zora pta doesn't report anything if there are any pending tests that don't wait for any events HOT 6
- Zora doesn't recognize differences bewteen Maps HOT 2
- The new timeout feature doesn't work correctly for serial tests (await) HOT 1
- pta reports PASS 0 before passing Zora tests finish running HOT 6
- How to know when all tests have completed? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zora.