Last active
May 5, 2020 13:03
-
-
Save qunabu/7071cb8f53bf0f523a69c3b389e015fa to your computer and use it in GitHub Desktop.
Strapi test helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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