Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Run mocha tests by npm scripts & Remove Gruntfile.js - Closes #2935 #3078

Merged
merged 32 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a2ca9c8
Build lisk mocha runner
yatki Mar 14, 2019
a16b02a
Add istanbul coverage support to lisk mocha runner
yatki Mar 14, 2019
adf0a62
Improve summary
yatki Mar 14, 2019
798d746
Fix testPathPattern option bug
yatki Mar 14, 2019
0e2c31d
Add new mocha npm scripts
yatki Mar 14, 2019
b86ee88
Throw exception for invalid test types
yatki Mar 14, 2019
c19ccf5
Remove Gruntfile.js
yatki Mar 14, 2019
e706697
Refactor lisk-mocha-runner
yatki Mar 14, 2019
80ba178
Update npm test command
yatki Mar 14, 2019
9baaebf
Refactor lisk mocha runner
yatki Mar 14, 2019
cc64781
Rename mochaOptions to mochaCliOptions
yatki Mar 14, 2019
a64271a
Fix mochaOptions bug & Set mocha.opts path
yatki Mar 14, 2019
7bbb1b3
Update Readme for lisk mocha runner
yatki Mar 14, 2019
92b1221
Update Jenkinsfiles for lisk mocha runner
yatki Mar 14, 2019
2b58a1c
Refactor new migration to remove grunt dependency
yatki Mar 14, 2019
ac89c36
Remove grunt from package.json
yatki Mar 14, 2019
b70959f
Add Licence headers to lisk mocha runner
yatki Mar 15, 2019
e2ada3f
Fix jenkinsfile syntax
yatki Mar 15, 2019
6228e5b
Remove sequential examples from Readme
yatki Mar 15, 2019
a300579
Increase the number of childs with environment variable on Jenkins
yatki Mar 15, 2019
2b892eb
Remove parallel_tests.js file
yatki Mar 15, 2019
4fe675e
Remove functional/http/put/index.js
yatki Mar 15, 2019
7dc1951
Fix indentation on Jenkinsfile
yatki Mar 15, 2019
d84d493
Remove webpack from devDependencies in .eslintrc.json
yatki Mar 15, 2019
c4eb556
Add copyright notice to new_migration.js
yatki Mar 15, 2019
3de21ab
Fix mocha:integration npm script
yatki Mar 15, 2019
53f1dc8
Fix mochaOptions in Jenkinsfile
yatki Mar 15, 2019
d766b87
Fix Jenkinsfile LISK_MOCHA_RUNNER_OPTIONS value examples.
yatki Mar 15, 2019
0675eee
Fix typo in Readme
yatki Mar 15, 2019
5f85b75
Add mocha:functional npm script
yatki Mar 15, 2019
3e9815d
Fix error code messages
yatki Mar 18, 2019
39c95e6
Remove index.js from test runner path
yatki Mar 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
"framework/test/**",
"test/**",
"framework/src/modules/chain/tasks/**",
"framework/src/modules/chain/scripts/**",
"webpack.config.js",
"Gruntfile.js"
"framework/src/modules/chain/scripts/**"
]
}
],
Expand Down
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ scripts/**/*
!scripts/generate_config.js
tasks/
test/
Grunt*
Jenkins*
*.sh
*.tgz
57 changes: 0 additions & 57 deletions Gruntfile.js

This file was deleted.

8 changes: 6 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run_test(test_name) {
ansiColor('xterm') {
timestamps {
nvm(getNodejsVersion()) {
sh 'npm test -- mocha:${JENKINS_PROFILE:-default}:' + "${test_name}"
sh 'npm run mocha:'+ "${test_name}" +' ${LISK_MOCHA_RUNNER_OPTIONS}'
}
}
}
Expand Down Expand Up @@ -81,7 +81,7 @@ def teardown(test_name) {

properties([
parameters([
string(name: 'JENKINS_PROFILE', defaultValue: '', description: 'To build cache dependencies and run slow tests, change this value to "extensive".', ),
string(name: 'LISK_MOCHA_RUNNER_OPTIONS', defaultValue: '-- --grep @slow|@unstable --invert', description: 'Please check readme to see available test tags. Example: `-- --grep something`', ),
// read by the application
string(name: 'LOG_LEVEL', defaultValue: 'error', description: 'To get desired build log output change the log level', ),
string(name: 'FILE_LOG_LEVEL', defaultValue: 'error', description: 'To get desired file log output change the log level', ),
Expand All @@ -95,6 +95,10 @@ properties([
pipeline {
agent { node { label 'lisk-core' } }

environment {
MAX_TASK_LIMIT = '20'
}

stages {
stage('Build') {
steps {
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile.extensive
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pipeline {
stages {
stage('Build extensive test suite') {
steps {
build job: "lisk-core/${env.BRANCH_NAME}", parameters: [string(name: 'JENKINS_PROFILE', value: 'extensive')]
build job: "lisk-core/${env.BRANCH_NAME}", parameters: [string(name: 'LISK_MOCHA_RUNNER_OPTIONS', value: '-- --grep @unstable --invert')]
build job: "lisk-core-network/${env.BRANCH_NAME}"
}
}
Expand Down
4 changes: 2 additions & 2 deletions Jenkinsfile.network
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

properties([
parameters([
string(name: 'JENKINS_PROFILE', defaultValue: '', description: 'To build cache dependencies and run slow tests, change this value to "extensive".', ),
string(name: 'LISK_MOCHA_RUNNER_OPTIONS', defaultValue: '', description: 'Please check readme to see available test tags. Example: `-- --grep something`', ),
// read by the application
string(name: 'LOG_LEVEL', defaultValue: 'error', description: 'To get desired build log output change the log level', ),
string(name: 'FILE_LOG_LEVEL', defaultValue: 'error', description: 'To get desired file log output change the log level', ),
Expand All @@ -42,7 +42,7 @@ pipeline {
steps {
ansiColor('xterm') {
nvm(getNodejsVersion()) {
sh 'npm test -- mocha:${JENKINS_PROFILE:-default}:network'
sh 'npm run mocha:network ${LISK_MOCHA_RUNNER_OPTIONS}'
}
}
}
Expand Down
54 changes: 41 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,28 +410,56 @@ Starting from version `1.6.0`, Lisk Core will be using [Jest](https://jestjs.io)
Tests are run using the following command:

```
npm test -- mocha:<tag>:<suite>:[section]
npm run mocha:<testType> -- [testPathPattern] [mochaCliOptions]
```

* Where **tag** can be one of `default | unstable | slow | extensive` (required)
* Where **suite** can be one of `unit | integration | functional | network` (required)
* Where **section** depending of the chosen suite can be:
* when `functional` --> `get | post | ws` (optional)
* Where **testType** can be one of `unit`, `integration`, `functional:ws`, `functional:get`, `functional:post`, `functional`, `network` (required).
* Where **testPathPattern** is a regexp pattern string that is matched against all tests paths before executing the test (optional).
* Where **mochaCliOptions** can be any of mocha's [`command line options`](https://mochajs.org/#command-line-usage) (optional).

Examples:

```
npm test -- mocha:slow:unit
npm test -- mocha:extensive:integration
npm test -- mocha:default:functional
npm test -- mocha:unstable:functional:get
npm test -- mocha:untagged:network
# Running network tests
npm run mocha:network
npm run mocha:network -- --grep @p2p
npm run mocha:network -- --grep @propagation

# Running unit tests
npm run mocha:unit
npm run mocha:unit -- --grep @slow
npm run mocha:unit -- --grep @unstable
### extensive
npm run mocha:unit -- --grep="@unstable" --invert

# Running Integration tests
npm run mocha:integration -- --grep @slow
npm run mocha:integration -- --grep @unstable
# extensive
npm run mocha:integration -- --grep="@unstable" --invert

# Running functional tests
npm run mocha:functional:ws
npm run mocha:functional:get
npm run mocha:functional:post
```

Individual test files can be run using the following commands:

```bash
npm run mocha:unit -- <testPathPattern> [mochaCliOptions]
```

Individual test files can be run using the following command:
or

```bash
npm run mocha <filepath> [mochaCliOptions]
```
npm run mocha -- path/to/test.js

or

```bash
npx mocha <filepath> [mochaCliOptions]
```

#### Running Jest Tests
Expand All @@ -445,7 +473,7 @@ npm run jest:<testType>
##### Executing the tests per file:

```
npm run jest:<testType> -- [filepath] [jest-options]
npm run jest:<testType> -- [testPathPattern] [jestCliOptions]
```

## Utility scripts
Expand Down
42 changes: 42 additions & 0 deletions framework/src/modules/chain/scripts/new_migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright © 2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

'use strict';

/* eslint-disable no-console */
yatki marked this conversation as resolved.
Show resolved Hide resolved

const moment = require('moment');
const fs = require('fs');

const createMigration = name => {
const migration = {
id: moment().format('YYYYMMDDHHmmss'),
name: String(name),
};
if (!migration.name.match(/^[a-z_]+$/i)) {
throw new Error('Invalid migration name');
}

migration.filename = `${migration.id}_${migration.name}.sql`;

console.log(`Creating migration file: ${migration.filename}`);

const filePath = `${__dirname}/../components/sql/migrations/updates/${
migration.filename
}`;

fs.writeFileSync(filePath, '');
};

module.exports = createMigration;
Empty file.
50 changes: 0 additions & 50 deletions framework/src/modules/chain/tasks/new_migration.js

This file was deleted.

62 changes: 62 additions & 0 deletions framework/test/mocha/common/lisk-mocha-runner/file_manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright © 2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

'use strict';

const find = require('find');
yatki marked this conversation as resolved.
Show resolved Hide resolved

const testTypesMap = {
unit: 'framework/test/mocha/unit/',
integration: 'framework/test/mocha/integration/',
'functional:ws': 'framework/test/mocha/functional/ws/',
'functional:get': 'framework/test/mocha/functional/http/get/',
'functional:post': 'framework/test/mocha/functional/http/post/',
yatki marked this conversation as resolved.
Show resolved Hide resolved
functional: 'framework/test/mocha/functional/',
network: 'framework/test/mocha/network/',
};

const scanFiles = testType => {
const folder = testTypesMap[testType];

if (testType === 'network') {
return [`${folder}index.js`];
}

if (folder) {
return find.fileSync(/^((?!common)[\s\S])*.js$/, folder);
}

throw new Error(
`Please specify a valid test type! Available Options: ${Object.keys(
testTypesMap
).join(', ')}`
);
};

const getTestFiles = (testType, testPathPattern) => {
const files = scanFiles(testType);

/**
* Filter file list with matching pattern
*/
if (testPathPattern) {
return files.filter(file => RegExp(testPathPattern, 'i').test(file));
}

return files;
};

module.exports = {
getTestFiles,
};
Loading