Refactor simple JS to be main JS tests

[MAILPOET-2455]
This commit is contained in:
Rostislav Wolny
2019-11-27 11:06:41 +01:00
committed by Jack Kitterhing
parent a6dfab1178
commit 6015a1370d
30 changed files with 29 additions and 16 deletions

View File

@ -178,11 +178,11 @@ jobs:
name: "JS Newsletter Editor Tests" name: "JS Newsletter Editor Tests"
command: | command: |
mkdir test-results/mocha mkdir test-results/mocha
./do t:j test-results/mocha/junit.xml ./do t:newsletter-editor test-results/mocha/newsletter_editor_junit.xml
- run: - run:
name: "JS Form Editor Tests" name: "JS Tests"
command: | command: |
npm test ./do t:j test-results/mocha/junit.xml
- store_test_results: - store_test_results:
path: test-results/mocha path: test-results/mocha
- store_artifacts: - store_artifacts:

2
.gitignore vendored
View File

@ -15,7 +15,7 @@ npm-debug.log
temp temp
.idea .idea
mailpoet.zip mailpoet.zip
tests/javascript/testBundles tests/javascript_newsletter_editor/testBundles
assets/dist assets/dist
.vagrant .vagrant
lang lang

View File

@ -204,13 +204,13 @@ class RoboFile extends \Robo\Tasks {
return $this->execWithXDebug($command); return $this->execWithXDebug($command);
} }
function testJavascript($xml_output_file = null) { function testNewsletterEditor($xml_output_file = null) {
$this->compileJs(); $this->compileJs();
$command = join(' ', [ $command = join(' ', [
'./node_modules/.bin/mocha', './node_modules/.bin/mocha',
'-r tests/javascript/mochaTestHelper.js', '-r tests/javascript_newsletter_editor/mochaTestHelper.js',
'tests/javascript/testBundles/**/*.js', 'tests/javascript_newsletter_editor/testBundles/**/*.js',
]); ]);
if (!empty($xml_output_file)) { if (!empty($xml_output_file)) {
@ -223,6 +223,19 @@ class RoboFile extends \Robo\Tasks {
return $this->_exec($command); return $this->_exec($command);
} }
function testJavascript($xml_output_file = null) {
$command = './node_modules/.bin/mocha --require @babel/register tests/javascript/**/*.spec.js';
if (!empty($xml_output_file)) {
$command .= sprintf(
' --reporter xunit --reporter-options output="%s"',
$xml_output_file
);
}
return $this->_exec($command);
}
function securityComposer() { function securityComposer() {
return $this->collectionBuilder() return $this->collectionBuilder()
->taskExec('vendor/bin/security-checker security:check --format=simple') ->taskExec('vendor/bin/security-checker security:check --format=simple')

View File

@ -11,13 +11,13 @@
], ],
"scripts": { "scripts": {
"lint": "npm run lint6 && npm run lint5 && npm run lint-tests", "lint": "npm run lint6 && npm run lint5 && npm run lint-tests",
"lint6": "eslint -c .eslintrc.es6.json --max-warnings 0 'assets/js/src/**/*.jsx'", "lint6": "eslint -c .eslintrc.es6.json --max-warnings 0 'assets/js/src/**/*.jsx' 'tests/javascript/**/*.js'",
"lint5": "eslint -c .eslintrc.es5.json --ignore-pattern helpscout.js --max-warnings 0 'assets/js/src/**/*.js' 'tests/javascript_form_editor/**/*.js'", "lint5": "eslint -c .eslintrc.es5.json --ignore-pattern helpscout.js --max-warnings 0 'assets/js/src/**/*.js'",
"lint-tests": "eslint -c .eslintrc.tests.json --max-warnings 0 'tests/javascript'", "lint-tests": "eslint -c .eslintrc.tests_newsletter_editor.json --max-warnings 0 'tests/javascript_newsletter_editor'",
"autoprefixer": "postcss assets/dist/css/*.css --use autoprefixer --no-map --replace", "autoprefixer": "postcss assets/dist/css/*.css --use autoprefixer --no-map --replace",
"scss": "node-sass assets/css/src/ --output assets/dist/css/ --output-style compact", "scss": "node-sass assets/css/src/ --output assets/dist/css/ --output-style compact",
"stylelint": "stylelint --fix", "stylelint": "stylelint --fix",
"test": "mocha --compilers js:@babel/register tests/javascript_form_editor/**/*.spec.js" "test": "mocha --require @babel/register tests/javascript/**/*.spec.js"
}, },
"dependencies": { "dependencies": {
"@babel/runtime": "^7.4.5", "@babel/runtime": "^7.4.5",

View File

@ -1,6 +1,6 @@
import { describe, it, beforeEach } from 'mocha'; import { describe, it, beforeEach } from 'mocha';
import { expect } from 'chai'; import { expect } from 'chai';
import reducer from '../../../../assets/js/src/form_editor/store/reducers/toggle_sidebar_panel.jsx'; import reducer from '../../../../../assets/js/src/form_editor/store/reducers/toggle_sidebar_panel.jsx';
describe('Toggle Sidebar Panel Reducer', () => { describe('Toggle Sidebar Panel Reducer', () => {
let initialState = null; let initialState = null;

View File

@ -34,7 +34,7 @@ global.jQuery = jQuery;
global.window.jQuery = jQuery; global.window.jQuery = jQuery;
testHelpers.loadScript('tests/javascript/testBundles/vendor.js', global.window); testHelpers.loadScript('tests/javascript_newsletter_editor/testBundles/vendor.js', global.window);
const Handlebars = global.window.Handlebars; const Handlebars = global.window.Handlebars;
global.Handlebars = global.window.Handlebars; global.Handlebars = global.window.Handlebars;

View File

@ -297,7 +297,7 @@ const migratorConfig = {
} }
}; };
// Test config // Newsletter Editor Tests Config
const testConfig = { const testConfig = {
name: 'test', name: 'test',
entry: { entry: {
@ -330,7 +330,7 @@ const testConfig = {
], ],
}, },
output: { output: {
path: path.join(__dirname, 'tests/javascript/testBundles'), path: path.join(__dirname, 'tests/javascript_newsletter_editor/testBundles'),
filename: '[name].js', filename: '[name].js',
}, },
plugins: [ plugins: [
@ -346,7 +346,7 @@ const testConfig = {
modules: [ modules: [
'node_modules', 'node_modules',
'assets/js/src', 'assets/js/src',
'tests/javascript/newsletter_editor' 'tests/javascript_newsletter_editor/newsletter_editor'
], ],
alias: { alias: {
'sticky-kit': 'vendor/jquery.sticky-kit.js', 'sticky-kit': 'vendor/jquery.sticky-kit.js',