You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docusaurus/static/llms-full.txt
+26-6Lines changed: 26 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -12293,6 +12293,10 @@ What the test harness does:
12293
12293
6. **User Permission Helper**: Patches the user service to automatically assign the "authenticated" role to newly created users, simplifying authentication tests
12294
12294
7. **Cleanup**: Properly closes connections and removes temporary database files after tests complete
12295
12295
12296
+
:::note
12297
+
The code example for the `tests/strapi.js` harness highlights lines 313-321 because these are optional, to be used if you [seed predictable test data](#optional-seed-predictable-test-data).
12298
+
:::
12299
+
12296
12300
Once these files are in place, the harness handles several Strapi 5 requirements automatically, letting you focus on writing actual test logic rather than configuration boilerplate.
12297
12301
12298
12302
## (optional) Seed predictable test data
@@ -12303,25 +12307,41 @@ Some API tests benefit from having a known set of documents preloaded. You can e
12303
12307
12304
12308
```js title="./scripts/seed.js"
12305
12309
async function seedExampleApp() {
12306
-
// Create content, upload files, set permissions, etc.
12310
+
// In test environment, skip complex seeding and just log
12311
+
if (process.env.NODE_ENV === 'test') {
12312
+
console.log('Test seeding: Skipping complex data import (not needed for basic tests)');
12313
+
return;
12314
+
}
12315
+
12316
+
const shouldImportSeedData = await isFirstRun();
12317
+
if (shouldImportSeedData) {
12318
+
try {
12319
+
console.log('Setting up the template...');
12320
+
await importSeedData();
12321
+
console.log('Ready to go');
12322
+
} catch (error) {
12323
+
console.log('Could not import seed data');
12324
+
console.error(error);
12325
+
}
12326
+
}
12307
12327
}
12308
12328
12329
+
// Allow usage both as a CLI and as a library from tests
12309
12330
if (require.main === module) {
12310
-
// still works as a CLI: `node ./scripts/seed.js`
12311
-
seedExampleApp().catch((err) => {
12312
-
console.error(err);
12331
+
main().catch((error) => {
12332
+
console.error(error);
12313
12333
process.exit(1);
12314
12334
});
12315
12335
}
12316
12336
12317
12337
module.exports = { seedExampleApp };
12318
12338
```
12319
12339
12320
-
2. In the test harness, call the function when `TEST_SEED=true`.
12340
+
2. In the test harness, call the function when `TEST_SEED=true` (see lines 313-321 highlighted in the code example from the [main test harness](#main-test-harness)).
12321
12341
12322
12342
3. Run your tests with seeding enabled:
12323
12343
12324
-
</Tabs>
12344
+
</Tabs>
12325
12345
12326
12346
Seeding runs after Strapi starts, so services, permissions, and uploads are available.
0 commit comments