Skip to content

Commit

Permalink
feat: added test:build script
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcaufy committed Apr 11, 2020
1 parent 88bfd92 commit 2f49bbe
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- run: npm run bootstrap
- run: npm run test
- run: npm run bootstrap:prod
- run: bash ./scripts/gen.sh
- run: npm run test:build
- name: Coverage Report
run: |
npm install coveralls && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"bootstrap": "./node_modules/.bin/lerna bootstrap --loglevel silly && ./scripts/install_dev.sh",
"bootstrap:prod": "./node_modules/.bin/lerna bootstrap --loglevel -- --production --no-optional && ./scripts/install_dev.sh",
"test": "npm run lint -- --fix && npm run test:cov",
"test:unit": "node ./scripts/unittest.js",
"test:unit": "node ./test/unit.js",
"test:cov": "nyc npm run test:unit",
"test:build": "./test/build.sh",
"clean": "./scripts/clean.sh",
"view": "./node_modules/.bin/verpub view -l",
"release": "./node_modules/.bin/verpub publish",
Expand Down
28 changes: 0 additions & 28 deletions scripts/exps/empty.exp

This file was deleted.

30 changes: 0 additions & 30 deletions scripts/exps/standard.exp

This file was deleted.

29 changes: 0 additions & 29 deletions scripts/exps/standard_non.exp

This file was deleted.

1 change: 0 additions & 1 deletion scripts/gen.sh → scripts/test-build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash


# test wepy new demo

# Start in tasks/ even if run from root directory
Expand Down
9 changes: 9 additions & 0 deletions test/build-cases/empty.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

name=$(basename "$0" .sh)
cd /tmp/templates/

wepy init empty $name --no-interactive

cd "$name"
npm install
9 changes: 9 additions & 0 deletions test/build-cases/standard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

name=$(basename "$0" .sh)
cd /tmp/templates/

wepy init standard $name --no-interactive --name test-interactive

cd "$name"
npm install
74 changes: 74 additions & 0 deletions test/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

# test wepy new demo

# Start in tasks/ even if run from root directory
cd "$(dirname "$0")"

function cleanup() {
echo 'Cleaning up.'
}


# Error messages are redirected to stderr
function handle_error() {
echo "$(basename $0): ERROR! An error was encountered executing line $1." 1>&2;
cleanup
echo 'Exiting with error.' 1>&2;
exit 1
}


function handle_exit() {
cleanup
echo 'Exiting without error.' 1>&2;
exit
}


# Exit the script with a helpful error message when any error is encountered
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR

# Cleanup before exit on any termination signal
trap 'set +x; handle_exit' SIGQUIT SIGTERM SIGINT SIGKILL SIGHUP

# Echo every command being executed
set -x


# Go to root
cd ..
root_path=$PWD


npm link packages/cli

wepy -v

wepy list

mkdir -p /tmp/templates/
cd /tmp/templates/

buildcases="${root_path}/test/build-cases"
for bc in ${buildcases}/*; do
name=$(basename $bc .sh)
"$root_path"/scripts/buildcases/"$name".sh
cd "/tmp/templates/${name}"
node "$root_path"/packages/cli/bin/wepy.js build
done

# Test build demos
cd /tmp/templates

# node "$root_path"/packages/cli/bin/wepy.js init wepyjs/wepy-wechat-demo wepy-wechat-demo
git clone https://github.com/wepyjs/wepy-wechat-demo.git --branch 2.0

cd wepy-wechat-demo
npm install
npm run build

cd ..

# Cleanup
cleanup
42 changes: 42 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const path = require('path');
const { spawnSync } = require('child_process');

const packages = [
'babel-plugin-import-regenerator',
'cli',
//'compiler-babel',
'compiler-less',
'compiler-sass',
//'compiler-stylus',
//'compiler-typescript',
'core',
'plugin-define'
//'plugin-eslint',
//'plugin-uglifyjs',
//'redux',
//'use-promisify',
//'x',
];

function testAll(pkgs) {
if (pkgs.length === 0) {
pkgs = packages;
}
pkgs.forEach(pkg => {
testOne(pkg);
});
}

function testOne(name) {
process.env.FORCE_COLOR = 1;
spawnSync('npm', ['run', 'test'], {
cwd: path.join(process.cwd(), 'packages', name),
env: process.env,
stdio: 'inherit'
});
}

// eslint-disable-next-line no-unused-vars
(function main([bin, file, ...args]) {
testAll(args);
})(process.argv);

0 comments on commit 2f49bbe

Please sign in to comment.