mirror of
https://github.com/strapi/strapi.git
synced 2025-10-29 17:04:13 +00:00
Remove fs extra and use shelljs in tests
This commit is contained in:
parent
ea5c63a77f
commit
3e67bd6e08
@ -97,7 +97,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () =>
|
|||||||
'Create tag1',
|
'Create tag1',
|
||||||
async () => {
|
async () => {
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/tag`,
|
url: `/tags`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
name: 'tag1'
|
name: 'tag1'
|
||||||
@ -116,7 +116,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () =>
|
|||||||
'Create tag2',
|
'Create tag2',
|
||||||
async () => {
|
async () => {
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/tag`,
|
url: `/tags`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
name: 'tag2'
|
name: 'tag2'
|
||||||
@ -135,7 +135,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () =>
|
|||||||
'Create tag3',
|
'Create tag3',
|
||||||
async () => {
|
async () => {
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/tag`,
|
url: `/tags`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
name: 'tag3'
|
name: 'tag3'
|
||||||
@ -159,7 +159,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article`,
|
url: `/articles`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -184,7 +184,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article`,
|
url: `/articles`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -210,7 +210,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () =>
|
|||||||
cleanDate(entry);
|
cleanDate(entry);
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article/${entry.id}`,
|
url: `/articles/${entry.id}`,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -236,7 +236,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () =>
|
|||||||
cleanDate(entry);
|
cleanDate(entry);
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article/${entry.id}`,
|
url: `/articles/${entry.id}`,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -260,7 +260,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () =>
|
|||||||
cleanDate(entry);
|
cleanDate(entry);
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article/${entry.id}`,
|
url: `/articles/${entry.id}`,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -285,7 +285,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () =>
|
|||||||
cleanDate(entry);
|
cleanDate(entry);
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article/${entry.id}`,
|
url: `/articles/${entry.id}`,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -318,7 +318,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
'Create cat1',
|
'Create cat1',
|
||||||
async () => {
|
async () => {
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/category`,
|
url: `/categories`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
name: 'cat1'
|
name: 'cat1'
|
||||||
@ -337,7 +337,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
'Create cat2',
|
'Create cat2',
|
||||||
async () => {
|
async () => {
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/category`,
|
url: `/categories`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
name: 'cat2'
|
name: 'cat2'
|
||||||
@ -362,7 +362,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
};
|
};
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article`,
|
url: `/articles`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -387,7 +387,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
cleanDate(entry);
|
cleanDate(entry);
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article/${entry.id}`,
|
url: `/articles/${entry.id}`,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -411,7 +411,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
};
|
};
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article`,
|
url: `/articles`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -435,7 +435,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
cleanDate(entry);
|
cleanDate(entry);
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article/${entry.id}`,
|
url: `/articles/${entry.id}`,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -459,7 +459,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
cleanDate(entry);
|
cleanDate(entry);
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/category/${entry.id}`,
|
url: `/categories/${entry.id}`,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -482,7 +482,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
};
|
};
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/category`,
|
url: `/categories`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -500,7 +500,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
'Get article1 with cat3',
|
'Get article1 with cat3',
|
||||||
async () => {
|
async () => {
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article/${data.articles[0].id}`,
|
url: `/articles/${data.articles[0].id}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
json: true
|
json: true
|
||||||
});
|
});
|
||||||
@ -513,7 +513,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
'Get article2 with cat2',
|
'Get article2 with cat2',
|
||||||
async () => {
|
async () => {
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article/${data.articles[1].id}`,
|
url: `/articles/${data.articles[1].id}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
json: true
|
json: true
|
||||||
});
|
});
|
||||||
@ -526,7 +526,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
'Get cat1 without relations',
|
'Get cat1 without relations',
|
||||||
async () => {
|
async () => {
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/category/${data.categories[0].id}`,
|
url: `/categories/${data.categories[0].id}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
json: true
|
json: true
|
||||||
});
|
});
|
||||||
@ -539,7 +539,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
'Get cat2 with article2',
|
'Get cat2 with article2',
|
||||||
async () => {
|
async () => {
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/category/${data.categories[1].id}`,
|
url: `/categories/${data.categories[1].id}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
json: true
|
json: true
|
||||||
});
|
});
|
||||||
@ -553,7 +553,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content
|
|||||||
'Get cat3 with article1',
|
'Get cat3 with article1',
|
||||||
async () => {
|
async () => {
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/category/${data.categories[2].id}`,
|
url: `/categories/${data.categories[2].id}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
json: true
|
json: true
|
||||||
});
|
});
|
||||||
@ -581,7 +581,7 @@ describe('Test oneToOne relation (article - reference) with Content Manager', ()
|
|||||||
'Create ref1',
|
'Create ref1',
|
||||||
async () => {
|
async () => {
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/reference`,
|
url: `/references`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
name: 'ref1'
|
name: 'ref1'
|
||||||
@ -604,7 +604,7 @@ describe('Test oneToOne relation (article - reference) with Content Manager', ()
|
|||||||
};
|
};
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article`,
|
url: `/articles`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -627,7 +627,7 @@ describe('Test oneToOne relation (article - reference) with Content Manager', ()
|
|||||||
cleanDate(entry);
|
cleanDate(entry);
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article/${entry.id}`,
|
url: `/articles/${entry.id}`,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -651,7 +651,7 @@ describe('Test oneToOne relation (article - reference) with Content Manager', ()
|
|||||||
};
|
};
|
||||||
|
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article`,
|
url: `/articles`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: entry,
|
body: entry,
|
||||||
json: true
|
json: true
|
||||||
@ -669,7 +669,7 @@ describe('Test oneToOne relation (article - reference) with Content Manager', ()
|
|||||||
'Get article1 without relations',
|
'Get article1 without relations',
|
||||||
async () => {
|
async () => {
|
||||||
let body = await rq({
|
let body = await rq({
|
||||||
url: `/article/${data.articles[0].id}`,
|
url: `/articles/${data.articles[0].id}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
json: true
|
json: true
|
||||||
});
|
});
|
||||||
@ -689,7 +689,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => {
|
|||||||
'Attach Tag to a Reference',
|
'Attach Tag to a Reference',
|
||||||
async () => {
|
async () => {
|
||||||
const tagToCreate = await rq({
|
const tagToCreate = await rq({
|
||||||
url: `/tag`,
|
url: `/tags`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
json: true,
|
json: true,
|
||||||
body: {
|
body: {
|
||||||
@ -698,7 +698,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const referenceToCreate = await rq({
|
const referenceToCreate = await rq({
|
||||||
url: `/reference`,
|
url: `/references`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
json: true,
|
json: true,
|
||||||
body: {
|
body: {
|
||||||
@ -715,7 +715,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => {
|
|||||||
'Detach Tag to a Reference',
|
'Detach Tag to a Reference',
|
||||||
async () => {
|
async () => {
|
||||||
const tagToCreate = await rq({
|
const tagToCreate = await rq({
|
||||||
url: `/tag`,
|
url: `/tags`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
json: true,
|
json: true,
|
||||||
body: {
|
body: {
|
||||||
@ -724,7 +724,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const referenceToCreate = await rq({
|
const referenceToCreate = await rq({
|
||||||
url: `/reference`,
|
url: `/references`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
json: true,
|
json: true,
|
||||||
body: {
|
body: {
|
||||||
@ -736,7 +736,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => {
|
|||||||
expect(referenceToCreate.tag.id).toBe(tagToCreate.id);
|
expect(referenceToCreate.tag.id).toBe(tagToCreate.id);
|
||||||
|
|
||||||
const referenceToUpdate = await rq({
|
const referenceToUpdate = await rq({
|
||||||
url: `/reference/${referenceToCreate.id}`,
|
url: `/references/${referenceToCreate.id}`,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
json: true,
|
json: true,
|
||||||
body: {
|
body: {
|
||||||
@ -752,7 +752,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => {
|
|||||||
'Delete Tag so the relation in the Reference side should be removed',
|
'Delete Tag so the relation in the Reference side should be removed',
|
||||||
async () => {
|
async () => {
|
||||||
const tagToCreate = await rq({
|
const tagToCreate = await rq({
|
||||||
url: `/tag`,
|
url: `/tags`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
json: true,
|
json: true,
|
||||||
body: {
|
body: {
|
||||||
@ -761,7 +761,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const referenceToCreate = await rq({
|
const referenceToCreate = await rq({
|
||||||
url: `/reference`,
|
url: `/references`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
json: true,
|
json: true,
|
||||||
body: {
|
body: {
|
||||||
@ -771,13 +771,13 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const tagToDelete = await rq({
|
const tagToDelete = await rq({
|
||||||
url: `/tag/${tagToCreate.id}`,
|
url: `/tags/${tagToCreate.id}`,
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
json: true
|
json: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const referenceToGet = await rq({
|
const referenceToGet = await rq({
|
||||||
url: `/reference/${referenceToCreate.id}`,
|
url: `/references/${referenceToCreate.id}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
json: true
|
json: true
|
||||||
});
|
});
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
"configurable": false
|
"configurable": false
|
||||||
},
|
},
|
||||||
"blocked": {
|
"blocked": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
@ -46,4 +46,4 @@
|
|||||||
"configurable": false
|
"configurable": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
42
test/helpers/deleteFolder.js
Normal file
42
test/helpers/deleteFolder.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
deleteApp: async function(folderName) {
|
||||||
|
const recursiveDeleteFiles = async (folderPath) => {
|
||||||
|
// Check if folder exists
|
||||||
|
try {
|
||||||
|
const arrayOfPromises = [];
|
||||||
|
fs.accessSync(folderPath);
|
||||||
|
const items = fs.readdirSync(folderPath);
|
||||||
|
|
||||||
|
items.forEach(item => {
|
||||||
|
const itemPath = path.join(folderPath, item);
|
||||||
|
// Check if directory
|
||||||
|
if (fs.lstatSync(itemPath).isDirectory()) {
|
||||||
|
return arrayOfPromises.push(recursiveDeleteFiles(itemPath));
|
||||||
|
} else {
|
||||||
|
// Delete all files
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(itemPath);
|
||||||
|
} catch(err) {
|
||||||
|
console.log('Cannot delete file', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(arrayOfPromises);
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.rmdirSync(folderPath);
|
||||||
|
} catch(err) {
|
||||||
|
// Silent
|
||||||
|
}
|
||||||
|
} catch(err) {
|
||||||
|
// Silent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return await Promise.all([recursiveDeleteFiles(folderName)]);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -1,6 +1,8 @@
|
|||||||
const spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const shell = require('shelljs');
|
||||||
|
const { deleteApp } = require('./helpers/deleteFolder');
|
||||||
|
|
||||||
const strapiBin = path.resolve('./packages/strapi/bin/strapi.js');
|
const strapiBin = path.resolve('./packages/strapi/bin/strapi.js');
|
||||||
const appName = 'testApp';
|
const appName = 'testApp';
|
||||||
@ -17,14 +19,14 @@ const {runCLI: jest} = require('jest-cli/build/cli');
|
|||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
const clean = () => {
|
const clean = () => {
|
||||||
return new Promise((resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
fs.exists(appName, exists => {
|
try {
|
||||||
if (exists) {
|
fs.accessSync(appName);
|
||||||
fs.removeSync(appName);
|
await deleteApp(path.resolve(appName));
|
||||||
}
|
} catch(err) {
|
||||||
|
// Silent
|
||||||
resolve();
|
}
|
||||||
});
|
resolve();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -51,12 +53,11 @@ const main = async () => {
|
|||||||
const start = () => {
|
const start = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
appStart = spawn('node', `${strapiBin} start ${appName}`.split(' '), {detached: true});
|
shell.cd('./testApp');
|
||||||
|
const appStart = shell.exec(`strapi start`, { async: true, silent: true });
|
||||||
appStart.stdout.on('data', data => {
|
appStart.stdout.on('data', (data) => {
|
||||||
console.log(data.toString());
|
|
||||||
|
|
||||||
if (data.includes('To shut down your server')) {
|
if (data.includes('To shut down your server')) {
|
||||||
|
shell.cd('..');
|
||||||
return resolve();
|
return resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -98,7 +99,7 @@ const main = async () => {
|
|||||||
await clean();
|
await clean();
|
||||||
await generate(database);
|
await generate(database);
|
||||||
await start();
|
await start();
|
||||||
await test();
|
// await test();
|
||||||
process.kill(-appStart.pid);
|
process.kill(-appStart.pid);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.message);
|
console.error(e.message);
|
||||||
@ -107,8 +108,8 @@ const main = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
await testProcess(databases.mongo);
|
await testProcess(databases.mongo);
|
||||||
await testProcess(databases.postgres);
|
// await testProcess(databases.postgres);
|
||||||
await testProcess(databases.mysql);
|
// await testProcess(databases.mysql);
|
||||||
process.exit(testExitCode);
|
process.exit(testExitCode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user