Skip to content

Instantly share code, notes, and snippets.

@qunabu
Last active May 5, 2020 13:03
Show Gist options
  • Save qunabu/7071cb8f53bf0f523a69c3b389e015fa to your computer and use it in GitHub Desktop.
Save qunabu/7071cb8f53bf0f523a69c3b389e015fa to your computer and use it in GitHub Desktop.
Strapi test helper
const fs = require("fs");
const Strapi = require("strapi");
let instance;
async function setupStrapi(entryNamesToOpen) {
if (!instance) {
//delete test database if exists
const testDataBase = `${__dirname}/../../.tmp/test.db`;
if (fs.existsSync(testDataBase)) {
fs.unlinkSync(testDataBase);
}
await Strapi().load();
instance = strapi; // strapi is global now
await instance.runBootstrapFunctions();
instance.app
.use(instance.router.routes()) // this code in copied from app/node_modules/strapi/lib/Strapi.js
.use(instance.router.allowedMethods());
}
return instance;
}
module.exports = { setupStrapi };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment