Skip to content

Commit

Permalink
Add package test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jichu4n committed Sep 11, 2024
1 parent 71c1dae commit 36faa5b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: Build
on: [push]
name: build
on: [push, pull_request]
jobs:
build:
name: Build qbjc and qbjc playground
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16]
node-version: [20]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install --legacy-peer-deps
- run: npm run --workspaces lint
- run: npm run --workspaces build
- run: npm run --workspace=qbjc test
- run: npm run --workspace=qbjc package-test
- run: npm run --workspace=monaco-qb test
- run: npm run --workspace=monaco-qb build:demo
1 change: 1 addition & 0 deletions qbjc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"build:nodeRuntimeBundle": "node ./dist/tools/build-runtime-bundle.js ./dist/runtime/node-runtime-bundle-bootstrap.js ./dist/runtime/node-runtime-bundle.js",
"build:tsc": "tsc && tsc -p tsconfig.platforms.json && chmod +x ./dist/qbjc.js",
"build": "npm run build:grammar && npm run build:tsc && npm run build:nodeRuntimeBundle",
"package-test": "npm run build && ./src/tests/package-test.sh",
"lint": "prettier --check .",
"test": "jest"
},
Expand Down
75 changes: 75 additions & 0 deletions qbjc/src/tests/package-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
#
# Smoke test for verifying the published package. It runs `npm pack` and
# verifies the output can be installed and imported.
#

TEST_SCRIPT=$(cat <<'EOF'
import assert from 'assert';
import {compile} from 'qbjc';
import {NodeExecutor} from 'qbjc/node';
async function testCompileAndRun(source: string) {
const {code} = await compile({
source,
sourceFileName: 'test.bas',
});
assert(code);
await new NodeExecutor().executeModule(code);
}
(async () => {
await testCompileAndRun('PRINT "Hello, World!"');
})();
EOF
)
SOURCE_DIR="$PWD"
TEMP_DIR="$PWD/../tmp-smoke-test"


cd "$SOURCE_DIR"
echo "> Building package"
npm pack || exit 1
echo

package_files=(*.tgz)
if [ ${#package_files[@]} -eq 1 ]; then
package_file="$SOURCE_DIR/${package_files[0]}"
echo "> Found package $package_file"
echo
else
echo "Could not identify package file"
exit 1
fi

echo "> Installing package in temp directory $TEMP_DIR"
if [ -d "$TEMP_DIR" ]; then
rm -rf "$TEMP_DIR"
fi
mkdir -p "$TEMP_DIR"
cd "$TEMP_DIR"
npm init -y
npm install --save ts-node typescript '@types/node' "$package_file"
echo '{ "compilerOptions": { "module": "CommonJS", "esModuleInterop": true } }' > tsconfig.json
echo

echo "> Running test script"
echo "$TEST_SCRIPT"
if ./node_modules/.bin/ts-node -e "$TEST_SCRIPT"; then
echo
echo "> Success!"
exit_code=0
else
exit_code=$?
echo
echo "> Error - script returned status ${exit_code}"
fi
echo

echo "> Cleaning up"
cd "$SOURCE_DIR"
rm -rf "$TEMP_DIR" "$package_file"

exit $exit_code

0 comments on commit 36faa5b

Please sign in to comment.