diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f16384729..8506a32de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/package.json b/package.json index 5f1eca531..c386a174b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/exps/empty.exp b/scripts/exps/empty.exp deleted file mode 100644 index a32ed5b4f..000000000 --- a/scripts/exps/empty.exp +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/expect -f - -set dist [lindex $argv 0] - -set timeout 30 - -spawn wepy init empty $dist - -expect "Target directory exists" -send "y\n" - -expect "Project name" -send "empty-project\n" - -expect "AppId" -send "\n" - -expect "Project description" -send "\n" - -expect "Author" -send "\n" -send "\n" -send "\n" - -send_user "\nEmpty template generated\n" - -interact diff --git a/scripts/exps/standard.exp b/scripts/exps/standard.exp deleted file mode 100644 index 6fa358e39..000000000 --- a/scripts/exps/standard.exp +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/expect -f - -set dist [lindex $argv 0] - -set timeout 30 - -spawn wepy init standard $dist - -expect "Project name" -send "standard-project\n" - -expect "AppId" -send "\n" - -expect "Project description" -send "\n" - -expect "Author" -send "\n" - -expect "Use ESLint to lint your code" -send "\n" - - -expect "Choose a state container" -send "jj\n" - -send_user "\nStandard template generated\n" - -interact diff --git a/scripts/exps/standard_non.exp b/scripts/exps/standard_non.exp deleted file mode 100644 index 456409fa1..000000000 --- a/scripts/exps/standard_non.exp +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/expect -f - -set dist [lindex $argv 0] - -set timeout 30 - -spawn wepy init standard $dist - -expect "Project name" -send "standard-project\n" - -expect "AppId" -send "\n" - -expect "Project description" -send "\n" - -expect "Author" -send "\n" - -expect "Use ESLint to lint your code" -send "n\n" - -expect "Choose a state container" -send "n\n" - -send_user "\nStandard template generated\n" - -interact diff --git a/scripts/gen.sh b/scripts/test-build.sh similarity index 99% rename from scripts/gen.sh rename to scripts/test-build.sh index 03697a257..a9182ffda 100755 --- a/scripts/gen.sh +++ b/scripts/test-build.sh @@ -1,6 +1,5 @@ #!/bin/bash - # test wepy new demo # Start in tasks/ even if run from root directory diff --git a/test/build-cases/empty.sh b/test/build-cases/empty.sh new file mode 100644 index 000000000..0e2decafc --- /dev/null +++ b/test/build-cases/empty.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +name=$(basename "$0" .sh) +cd /tmp/templates/ + +wepy init empty $name --no-interactive + +cd "$name" +npm install diff --git a/test/build-cases/standard.sh b/test/build-cases/standard.sh new file mode 100644 index 000000000..878cc23db --- /dev/null +++ b/test/build-cases/standard.sh @@ -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 diff --git a/test/build.sh b/test/build.sh new file mode 100644 index 000000000..840bcbba6 --- /dev/null +++ b/test/build.sh @@ -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 diff --git a/test/unit.js b/test/unit.js new file mode 100644 index 000000000..1d076af05 --- /dev/null +++ b/test/unit.js @@ -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);