Change test logic

This commit is contained in:
soupette 2018-05-04 15:38:42 +02:00
parent 1a68f3ea9f
commit f9f78745ca
7 changed files with 91 additions and 8 deletions

View File

@ -4,6 +4,7 @@
"devDependencies": {
"assert": "~1.3.0",
"babel-eslint": "^6.1.2",
"chalk": "^2.4.1",
"eslint": "^3.12.2",
"eslint-plugin-babel": "^4.0.0",
"eslint-plugin-react": "^6.8.0",

View File

@ -156,8 +156,7 @@ export class AdminPage extends React.Component { // eslint-disable-line react/pr
const { adminPage } = this.props;
const header = this.showLeftMenu() ? <Header /> : '';
const style = this.showLeftMenu() ? {} : { width: '100%' };
const c = '';
return (
<div className={styles.adminPage}>
{this.showLeftMenu() && (

View File

@ -18,10 +18,8 @@
"prestart": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/cross-env NODE_ENV=development PORT=4000 IS_ADMIN=true node ./node_modules/strapi-helper-plugin/lib/internals/scripts/loadAdminConfigurations.js",
"start": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/cross-env NODE_ENV=development PORT=4000 IS_ADMIN=true node ./node_modules/strapi-helper-plugin/lib/server",
"generate": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/plop --plopfile ./node_modules/strapi-helper-plugin/lib/internals/generators/index.js",
"lint:front": "node ./node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern '/admin/build/' --config ./node_modules/strapi-lint/lib/internals/eslint/front/.eslintrc.json admin",
"lint:back": "node ./node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern '/admin/build/' --config ./node_modules/strapi-lint/lib/internals/eslint/back/.eslintrc.json controllers config services",
"prettier": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/prettier --single-quote --trailing-comma es5 --write \"{admin,__{tests,mocks}__}/**/*.js\"",
"test": "npm run lint:front && npm run lint:back",
"test": "echo \"Error: no test specified\"",
"prepublishOnly": "npm run build",
"setup": "node ./scripts/setup.js",
"presetup": "node ./scripts/preSetup.js"
@ -53,4 +51,4 @@
"npm": ">= 5.0.0"
},
"license": "MIT"
}
}

View File

@ -68,7 +68,7 @@
"settings": {
"import/resolver": {
"webpack": {
"config": "node_modules/strapi-lint/lib/internals/webpack/webpack.test.babel.js"
"config": "../../node_modules/strapi-lint/lib/internals/webpack/webpack.test.babel.js"
}
}
}

View File

@ -106,7 +106,7 @@
"settings": {
"import/resolver": {
"webpack": {
"config": "node_modules/strapi-lint/lib/internals/webpack/webpack.test.babel.js"
"config": "../../node_modules/strapi-lint/lib/internals/webpack/webpack.test.babel.js"
}
}
}

View File

@ -0,0 +1,57 @@
const chalk = require('chalk');
const blue = chalk.blue;
const yellow = chalk.yellow;
const green = chalk.green;
const red = chalk.red;
const magenta = chalk.magenta;
const eslintErrorsFormatter = data => {
const errors = data.split('\n\n');
const formattedErrors = errors.reduce((acc, curr, i) => {
if (curr.includes('warnings)') || curr.includes('warning)')) {
const summaryErrorArray = curr.split(' ');
const summaryError = `${red(summaryErrorArray[0])} ${green(
`${summaryErrorArray[1]} ${summaryErrorArray[2]}`,
)} ${summaryErrorArray.slice(3).join(' ')}`;
acc.push(summaryError);
} else {
const err = curr.split('\n').reduce((acc, c) => {
const error = c
.split(' ')
.reduce((acc, current, index) => {
let formattedError;
switch (index) {
case 0:
formattedError = blue(current);
break;
case 4:
formattedError = current === 'warning' ? green(current) : red(current);
break;
case c.split(' ').length - 1:
formattedError = yellow(current);
break;
default:
formattedError = current;
}
acc.push(formattedError);
return acc;
}, [])
.join(' ');
acc.push(error);
return acc;
}, []);
acc.push(err.join('\n'));
}
return acc;
}, []);
return formattedErrors.join('\n\n');
};
module.exports = eslintErrorsFormatter;

28
scripts/lint.js Normal file
View File

@ -0,0 +1,28 @@
const path = require('path');
const shell = require('shelljs');
const chalk = require('chalk');
const eslintErrorsFormatter = require('./eslintErrorsFormatter');
const frontCmd =
'node ../../node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern \'/admin/build/\' --config ../../node_modules/strapi-lint/lib/internals/eslint/front/.eslintrc.json admin';
const backCmd =
'node ../../node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern \'/admin\' --config ../../node_modules/strapi-lint/lib/internals/eslint/back/.eslintrc.json controllers config services';
const watcher = (label, pckgName, type = 'front') => {
shell.echo(label);
const cmd = type === 'front' ? frontCmd : backCmd;
shell.cd(`packages/${pckgName}`);
const data = shell.exec(`${frontCmd} && ${backCmd}`, { silent: true });
shell.echo(chalk(eslintErrorsFormatter(data.stdout)));
shell.cd('../..');
if (data.code !== 0) {
process.exit(1);
}
shell.echo(`Lint tests passed in ${pckgName}`);
};
shell.echo('Testing lint');
watcher('testing admin', 'strapi-admin');
watcher('testing content-manager', 'strapi-plugin-content-manager');