Skip to content

Commit

Permalink
chore: run tests parallely
Browse files Browse the repository at this point in the history
  • Loading branch information
aadityataparia committed Jul 4, 2019
1 parent 392737a commit 9db41ba
Show file tree
Hide file tree
Showing 6 changed files with 869 additions and 80 deletions.
14 changes: 6 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
steps:
- add_ssh_keys:
fingerprints:
- "22:0a:b8:85:e7:5a:96:2a:90:5c:16:01:d6:1f:e8:b6"
- '22:0a:b8:85:e7:5a:96:2a:90:5c:16:01:d6:1f:e8:b6'
- restore_cache:
keys:
- sifrr-elements-v1-source-{{ .Branch }}-{{ .Revision }}
Expand All @@ -17,7 +17,7 @@ jobs:
- save_cache:
key: sifrr-elements-v1-source-{{ .Branch }}-{{ .Revision }}
paths:
- ".git"
- '.git'
- restore_cache:
keys:
- sifrr-v1-yarn-{{ checksum "yarn.lock" }}
Expand All @@ -33,16 +33,14 @@ jobs:
name: Check chrome version
command: google-chrome --version
- run:
name: Add git user email and name
name: Add git user email and name and Update files
command: |
git config --global user.email "aadityataparia@gmail.com"
git config --global user.email "aadityataparia@gmail.com" || exit 0
git config --global user.name "Aaditya Taparia"
- run:
name: Update dist files
command: ./scripts/distribute
./scripts/distribute
- run:
name: Run tests
command: COVERAGE=true LCOV=true yarn test -j
command: PARALLEL=true COVERAGE=true LCOV=true yarn test -j
- run:
name: New Release
command: |
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
extends: ['sifrr']
extends: ['@sifrr']
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@sifrr/storage": "^0.0.5"
},
"devDependencies": {
"@sifrr/dev": "0.0.13"
"@sifrr/dev": "0.0.19"
},
"dependencies": {
"@sifrr/animate": "^0.0.3",
Expand Down
72 changes: 41 additions & 31 deletions scripts/test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const runBrowserTests = process.argv.indexOf('-b') > 0 || process.argv.indexOf('
const serverOnly = process.argv.indexOf('-s') > 0 || process.argv.indexOf('--server') > 0;

// test port
let port = 8888;
const portIndex = Math.max(process.argv.indexOf('--test-port'), process.argv.indexOf('-tp'));
if (portIndex !== -1) {
port = +process.argv[portIndex + 1];
}
// let port = 8888;
// const portIndex = Math.max(process.argv.indexOf('--test-port'), process.argv.indexOf('-tp'));
// if (portIndex !== -1) {
// port = +process.argv[portIndex + 1];
// }

// check if need to filter
let filters;
Expand All @@ -36,32 +36,42 @@ if (filter > 0) {
const reporters = ['html'];
if (process.env.LCOV === 'true') reporters.push('lcov');

const root = path.join(__dirname, '../../', process.argv[2]) || path.resolve('./');
const roots = (process.argv[2] || './')
.split(/[ ,\n]/g)
.map(p => path.join(__dirname, '../../', p));

const options = roots.map(root => {
return {
root,
serverOnly,
runUnitTests,
runBrowserTests,
coverage,
filters,
port: 'random',
useJunitReporter,
inspect,
folders: {
static: [path.join(__dirname, '../../dist')],
coverage: path.join(__dirname, '../../.nyc_output'),
source: path.join(__dirname, '../../elements')
},
sourceFileRegex: /sifrr-[a-z-]+\/src\/.*\.js$/,
junitXmlFile: path.join(__dirname, `../../test-results/${path.basename(root)}/results.xml`),
reporters
};
});

const { runTests } = require('@sifrr/dev');

runTests({
root,
serverOnly,
runUnitTests,
runBrowserTests,
coverage,
filters,
port,
useJunitReporter,
inspect,
folders: {
static: [path.join(__dirname, '../../dist')],
coverage: path.join(__dirname, '../../.nyc_output'),
source: path.join(__dirname, '../../elements')
},
sourceFileRegex: /sifrr-[a-z-]+\/src\/.*\.js$/,
junitXmlFile: path.join(__dirname, `../../test-results/${path.basename(root)}/results.xml`),
reporters
})
.then(() => global.console.log(`All tests passed`))
.catch(e => {
if (Number(e)) global.console.log(`${e} tests failed!`);
else global.console.error(e);
process.exit(1);
});
runTests(options.length === 0 ? options[0] : options, process.env.PARALLEL === 'true').then(
({ failures, coverage }) => {
console.table(coverage);
if (failures > 0) {
global.console.error(`${failures} tests failed`);
process.exit(1);
}
global.console.log('All tests passed.');
process.exit(0);
}
);
12 changes: 5 additions & 7 deletions scripts/test/runall
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ if [[ $COVERAGE == 'true' ]]; then
rm -rf ./.nyc_output
fi

for dir in ./elements/*
do
echo "Running test in ${dir}:"
node ./scripts/test/run.js "${dir}" "$@"
dirs=(./elements/*)
dirsc=$(echo "${dirs[@]}")
node ./scripts/test/run.js "${dirsc}" "$@"

NEW_STATUS=$?
[ $NEW_STATUS -eq 0 ] || STATUS=$NEW_STATUS
done
NEW_STATUS=$?
[ $NEW_STATUS -eq 0 ] || STATUS=$NEW_STATUS

if [[ $COVERAGE == 'true' ]]; then
if [[ $LCOV == 'true' ]]; then
Expand Down
Loading

0 comments on commit 9db41ba

Please sign in to comment.