Add writeFixture()
and clearFixture()
methods
#599
Replies: 4 comments 7 replies
-
Ah.. This reminded me the file System API from Japa: https://japa.dev/docs/plugins/file-system#file-system-api |
Beta Was this translation helpful? Give feedback.
-
Probably as an instanced class, like:
// improvised name
useFixtures([
{
path: '.temp/foo.txt',
content: '🐷',
},
]);
test(() => { /* ... */ });
const fixtures = useFixtures([
{
path: '.temp/foo.txt',
content: '🐷',
},
]);
await fixtures.write(); // optional (should be called automatically as a `beforeEach`)
await fixtures.clear(); // optional (should be called automatically as a `afterEach`) In that approach, it would be a kind of replacement for the |
Beta Was this translation helpful? Give feedback.
-
I looked through the codebase. In most of the cases fixtures are created for each test scope: await describe("test scope", async () => {
await test("first test", async () => {
await writeFixture();
// test logic
await clearFixture();
});
await test("second test", async () => {
await writeFixture();
// test logic
await clearFixture();
});
}); Sometimes all tests in a await describe("describe scope x", async () => {
await writeFixture();
for (const testCase of testCases) {
await test(testCase, async () => {
// test logic
});
}
await clearFixture();
});
await describe("describe scope y", async () => {
await writeFixture();
await test("first test", async () => {
// test logic
});
await test("second test", async () => {
// test logic
});
await clearFixture();
}); At the moment there are no per file fixtures, i.e. I think fixture should be created and disposed per scope, not globally. Somewhat similar to the So here is the proposed API: await describe("test scope", async () => {
await test("first test", async () => {
await usingFixture(fixtureUrl, {
["dummyFile.js"]: dummyFileText,
["tsconfig.json"]: JSON.stringify(tsconfig, null, 2),
});
// test logic
// the fixture is disposed by Poku
});
await test("second test", async () => {
await usingFixture(fixtureUrl, {
["dummyFile.js"]: dummyFileText,
["tsconfig.json"]: JSON.stringify(tsconfig, null, 2),
});
// test logic
// the fixture is disposed by Poku
});
}); The await describe("describe scope one", async () => {
await usingFixture(fixtureUrl, {
["dummyFile.js"]: dummyFileText,
["tsconfig.json"]: JSON.stringify(tsconfig, null, 2),
});
for (const testCase of testCases) {
await test(testCase, async () => {
// test logic
});
}
// the fixture is disposed by Poku
});
await describe("describe scope two", async () => {
await usingFixture(fixtureUrl, {
["dummyFile.js"]: dummyFileText,
["tsconfig.json"]: JSON.stringify(tsconfig, null, 2),
});
await test("first test", async () => {
// test logic
});
await test("second test", async () => {
// test logic
});
// the fixture is disposed by Poku
}); And even global scope should work. Notes:
|
Beta Was this translation helpful? Give feedback.
-
Sounds right. I was thinking: if next The same with It feels like |
Beta Was this translation helpful? Give feedback.
-
What if Poku would have
writeFixture()
andclearFixture()
methods?These are easy to implement on user side, but Poku implementation could:
fs
of each platform (if that makes sense in this case?)Bonus: perhaps Poku could use these methods in its own tests (;
I am not 100% sure if that is good idea. Just wanted to leave a note.
Beta Was this translation helpful? Give feedback.
All reactions