chore: Add integration test for the importOnBootstrap setting

pull/111/head
Boaz Poolman 2023-10-19 08:19:06 +02:00
parent 7573cfd75c
commit 3b7084fa87
4 changed files with 92 additions and 3 deletions

View File

@ -6,7 +6,6 @@ const exec = util.promisify(require('child_process').exec);
jest.setTimeout(20000); jest.setTimeout(20000);
describe('Test the config-sync CLI', () => { describe('Test the config-sync CLI', () => {
afterAll(async () => { afterAll(async () => {
// Remove the generated files and the DB. // Remove the generated files and the DB.
await exec('rm -rf config/sync'); await exec('rm -rf config/sync');

View File

@ -0,0 +1,34 @@
const fs = require('fs');
const Strapi = require('@strapi/strapi');
let instance;
async function setupStrapi() {
if (!instance) {
await Strapi().load();
instance = strapi;
await instance.server.mount();
}
return instance;
}
async function cleanupStrapi() {
const dbSettings = strapi.config.get('database.connection');
// close server to release the db-file.
await strapi.server.httpServer.close();
// close the connection to the database before deletion.
await strapi.db.connection.destroy();
// delete test database after all tests have completed.
if (dbSettings && dbSettings.connection && dbSettings.connection.filename) {
const tmpDbFile = dbSettings.connection.filename;
if (fs.existsSync(tmpDbFile)) {
fs.unlinkSync(tmpDbFile);
}
}
}
module.exports = { setupStrapi, cleanupStrapi };

View File

@ -0,0 +1,48 @@
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const { setupStrapi, cleanupStrapi } = require('./helpers');
jest.setTimeout(20000);
afterAll(async () => {
// Disable importOnBootstrap
await exec('gsed -i "s/importOnBootstrap: true/importOnBootstrap: false/g" config/plugins.js');
await cleanupStrapi();
await exec('rm -rf config/sync');
});
describe('Test the importOnBootstrap feature', () => {
test('Without a database', async () => {
// Do the initial export and remove the database.
await exec('yarn cs export -y');
await exec('rm -rf .tmp');
// Manually change the plugins.js to enable importOnBoostrap.
await exec('gsed -i "s/importOnBootstrap: false/importOnBootstrap: true/g" config/plugins.js');
// Start up Strapi to initiate the importOnBootstrap function.
await setupStrapi();
expect(strapi).toBeDefined();
});
test('With a database', async () => {
// Delete any existing database and do an export.
await exec('rm -rf .tmp');
await exec('yarn cs export -y');
// Manually change the plugins.js to enable importOnBoostrap.
await exec('gsed -i "s/importOnBootstrap: false/importOnBootstrap: true/g" config/plugins.js');
// Remove a config file to make sure the importOnBoostrap
// function actually attempts to import.
await exec('rm -rf config/sync/admin-role.strapi-editor.json');
// Start up Strapi to initiate the importOnBootstrap function.
await setupStrapi();
expect(strapi).toBeDefined();
});
});

View File

@ -0,0 +1,8 @@
module.exports = {
'config-sync': {
enabled: true,
config: {
importOnBootstrap: false,
},
},
};