From 48e8a74163fa77b028d97d63f5c8f96ddb4d03c7 Mon Sep 17 00:00:00 2001 From: Andreas Richter <708186+richtera@users.noreply.github.com> Date: Mon, 17 Jul 2023 05:41:26 -0400 Subject: [PATCH] fix: Add test script to validate import/require --- .github/workflows/build-lint-test.yml | 3 + package.json | 1 + tests/importRequire.sh | 118 ++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100755 tests/importRequire.sh diff --git a/.github/workflows/build-lint-test.yml b/.github/workflows/build-lint-test.yml index 06ce1313a..f00f41c34 100644 --- a/.github/workflows/build-lint-test.yml +++ b/.github/workflows/build-lint-test.yml @@ -97,3 +97,6 @@ jobs: - name: 🧪 run tests run: npm run test:${{ matrix.lsp }} + + - name: 🧪 run import/requires tests + run: npm run test:import diff --git a/package.json b/package.json index 27d85beb7..dd18d3f2f 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "test:reentrancy": "hardhat test --no-compile tests/Reentrancy/Reentrancy.test.ts", "test:reentrancyinit": "hardhat test --no-compile tests/Reentrancy/ReentrancyInit.test.ts", "test:foundry": "forge test --no-match-test Skip -vvv --gas-report > gasreport.ansi", + "test:importRequire": "npm run build && npm run build:js && ./tests/importRequire.sh", "clean": "hardhat clean && rm -rf module common", "build": "hardhat dodoc && ts-node scripts/interfaceIds.ts && prettier -w ./docs ", "build:js": "vite build && dts-bundle-generator --config dtsconfig.json", diff --git a/tests/importRequire.sh b/tests/importRequire.sh new file mode 100755 index 000000000..0712e823e --- /dev/null +++ b/tests/importRequire.sh @@ -0,0 +1,118 @@ +#!/usr/bin/env bash +mktmp=$(mktemp -d) +trap "rm -rf $mktmp" EXIT +RED="\033[31m" +GREEN="\033[32m" +YELLOW="\033[33m" +ENDCOLOR="\033[0m" + +if [ ! -f './dist/constants.cjs.js' ] +then + echo -e "${RED}Fail: No constants.cjs.js found${ENDCOLOR}" + exit 1 +fi +if [ ! -f './dist/constants.es.js' ] +then + echo -e "${RED}Fail: No constants.es.js found${ENDCOLOR}" + exit 1 +fi +if [ ! -f './package.json' ] +then + echo -e "${RED}Fail: No package.json found${ENDCOLOR}" + exit 1 +fi + +echo -e "${YELLOW}Packaging npm package${ENDCOLOR}" +npm pack + +PACK="$(pwd)/$(ls | grep -E "^lukso.*tgz$")" +if [ ! -f "$PACK" ] +then + echo -e "${RED}Fail: No tgz pack file found${ENDCOLOR}" + exit 1 +fi + +echo -e "${YELLOW}Creating test directory${ENDCOLOR}" +cd $mktmp + +echo -e "${YELLOW}Installing $PACK" +npm install "$PACK" + +echo -e "${YELLOW}Creating cjs require test${ENDCOLOR}" +cat > test.cjs < test.ts < package.json < tsconfig.json <