Skip to content

Commit

Permalink
chore: add integration test for create fuels (#2489)
Browse files Browse the repository at this point in the history
  • Loading branch information
petertonysmith94 authored Jun 24, 2024
1 parent 04b58e2 commit 2290935
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-jokes-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-fuels": patch
---

chore: add integration test for `create fuels`
57 changes: 33 additions & 24 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ jobs:
path: coverage/environments/${{ matrix.env.name }}
overwrite: true

e2e:
integration:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [environments]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -60,32 +59,36 @@ jobs:
- name: Test Setup
uses: ./.github/actions/test-setup
with:
should-install-bun: true

- name: Publish PR to NPM
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
id: release
uses: ./.github/actions/pr-release
with:
npm-token: ${{ secrets.NPM_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
should-install-bun: github.ref_name == 'master' || github.head_ref == 'changesets-release/master'

- name: Echo Published Version
run: echo ${{ steps.release.outputs.published_version }}
- name: Run UI tests (on template)
run: sh ./scripts/tests-ui.sh

- name: Pretest
run: pnpm pretest
- name: Wait for release to succeed
if: github.ref_name == 'master' || github.head_ref == 'changesets-release/master'
uses: lewagon/wait-on-check-action@v1.3.4
with:
ref: 'refs/heads/master'
check-name: "Release"
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 30

- name: Run tests (with published version)
if: github.ref_name == 'master' || github.head_ref == 'changesets-release/master'
run: pnpm test:integration
env:
PUBLISHED_NPM_VERSION: next

- name: Run Isolated Tests
run: pnpm test:e2e
- name: Run UI tests (with published version)
if: github.ref_name == 'master' || github.head_ref == 'changesets-release/master'
run: sh ./scripts/create-fuels-template-integration.sh
env:
TESTNET_WALLET_PVT_KEY: ${{ secrets.TESTNET_WALLET_PVT_KEY }}
DEVNET_WALLET_PVT_KEY: ${{ secrets.DEVNET_WALLET_PVT_KEY }}
PUBLISHED_NPM_VERSION: ${{ steps.release.outputs.published_version }}
PUBLISHED_NPM_VERSION: next

create-fuels-template-integration:
timeout-minutes: 10
e2e:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [environments]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -95,8 +98,14 @@ jobs:
- name: Test Setup
uses: ./.github/actions/test-setup

- name: Run UI tests
run: sh ./scripts/create-fuels-template-integration.sh
- name: Pretest
run: pnpm pretest

- name: Run Isolated Tests
run: pnpm test:e2e
env:
TESTNET_WALLET_PVT_KEY: ${{ secrets.TESTNET_WALLET_PVT_KEY }}
DEVNET_WALLET_PVT_KEY: ${{ secrets.DEVNET_WALLET_PVT_KEY }}

test:
if: github.base_ref == 'master' || github.ref_name == 'master'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"test:browser": "vitest --run --coverage --config vitest.browser.config.mts $(scripts/tests-find.sh --browser)",
"test:browser:filter": "vitest --run --coverage false --config vitest.browser.config.mts",
"test:e2e": "vitest --run --config vitest.node.config.mts $(scripts/tests-find.sh --e2e)",
"test:integration": "vitest --run --config vitest.node.config.mts $(scripts/tests-find.sh --integration)",
"lint": "run-s lint:check prettier:check",
"lint:check": "eslint . --ext .ts --max-warnings 0",
"lint:fix": "pnpm lint:check --fix",
Expand Down
1 change: 1 addition & 0 deletions packages/create-fuels/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const runScaffoldCli = async ({

process.chdir(projectPath);
execSync(packageManager.install, { stdio: verboseEnabled ? 'inherit' : 'pipe' });

installDepsSpinner.succeed('Installed dependencies!');
}

Expand Down
4 changes: 2 additions & 2 deletions packages/create-fuels/src/lib/setupProgram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { setupProgram } from './setupProgram';
describe('setupProgram', () => {
test('setupProgram takes in args properly', () => {
const program = setupProgram();
program.parse(['', '', 'test-project-name', '--pnpm', '--npm']);
program.parse(['', '', 'test-project-name', '--pnpm', '--npm', '--bun']);
expect(program.args[0]).toBe('test-project-name');
expect(program.opts().pnpm).toBe(true);
expect(program.opts().npm).toBe(true);
expect(program.opts().bun).toBe(undefined);
expect(program.opts().bun).toBe(true);
});

test('setupProgram - no args', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const packageManagerCreateCommands: [PackageManager, string][] = [
];

/**
* @group e2e
* @group integration
*/
describe('`create fuels` package integrity', () => {
let paths: ProjectPaths;
Expand Down
7 changes: 0 additions & 7 deletions scripts/create-fuels-template-integration.sh

This file was deleted.

2 changes: 2 additions & 0 deletions scripts/tests-find.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ elif [[ $* == *--browser* ]]; then
grep -lE "@group\s+browser" $FILES
elif [[ $* == *--e2e* ]]; then
grep -lE "@group\s+e2e" $FILES
elif [[ $* == *--integration* ]]; then
grep -lE "@group\s+integration" $FILES
fi
50 changes: 50 additions & 0 deletions scripts/tests-ui-integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# The PUBLISHED_NPM_VERSION variable is required to create a new project with the current published `fuels` version
PUBLISHED_NPM_VERSION="${PUBLISHED_NPM_VERSION-"next"}"

# Versions
FUEL_CORE_VERSION=$(cat ./internal/fuel-core/VERSION)
FORC_VERSION=$(cat ./internal/forc/VERSION)
TOOLCHAIN="CI"

# Project
ROOT_DIR=$(pwd)
PLAYWRIGHT_DIR="$ROOT_DIR"
PROJECT_DIR="$ROOT_DIR/test-project"

echo "1. Install toolchains"
if [ -x "$(command -v fuelup)" ]; then
echo "Fuelup exists"
else
echo "Fuelup does not exist - installing 'fuelup'"
curl -fsSL https://install.fuel.network/ | sh -s -- --no-modify-path
export PATH="${HOME}/.fuelup/bin:${PATH}"
fi

fuelup toolchain new $TOOLCHAIN
fuelup default $TOOLCHAIN
fuelup component add fuel-core@$FUEL_CORE_VERSION
fuelup component add forc@$FORC_VERSION

echo "2. Scaffold a new project with 'create fuels@$PUBLISHED_NPM_VERSION'"
if [ -d "$PROJECT_DIR" ]; then
echo "Removing existing project directory '$PROJECT_DIR'"
rm -rf $PROJECT_DIR
fi
pnpm create fuels@$PUBLISHED_NPM_VERSION $PROJECT_DIR --pnpm -cps --no-install

echo "3. Intialise the project"
cd $PROJECT_DIR
pnpm add fuels@$PUBLISHED_NPM_VERSION > /dev/null 2>&1
pnpm --ignore-workspace install > /dev/null 2>&1
cp .env.example .env.local

echo "4. Running UI tests"
cd $ROOT_DIR
PROJECT_DIR=$PROJECT_DIR sh ./scripts/tests-ui.sh
TEST_RESULT=$?

rm -rf $PROJECT_DIR

exit $TEST_RESULT
18 changes: 18 additions & 0 deletions scripts/tests-ui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

ROOT_DIR=$(pwd)
PLAYWRIGHT_DIR="$ROOT_DIR"
PROJECT_DIR="${PROJECT_DIR-"$ROOT_DIR/templates/nextjs"}"

cd $PROJECT_DIR && pnpm run fuels:dev > /dev/null 2>&1 &
sleep 5

cd $PROJECT_DIR && pnpm run dev > /dev/null 2>&1 &
sleep 5

cd $PLAYWRIGHT_DIR
pnpm exec playwright install --with-deps
pnpm exec playwright test

pkill next-server
pkill fuel-core
2 changes: 1 addition & 1 deletion scripts/tests-validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ROOT=$(cd "$(dirname "$0")/.."; pwd)

FILES=$(find $ROOT/{apps,packages,internal} -name '*.test.ts')
INVALID_FILES=$(grep -LE "@group\s+(node|browser|e2e)" $FILES)
INVALID_FILES=$(grep -LE "@group\s+(node|browser|e2e|integration)" $FILES)

if [ ! -z "$INVALID_FILES" ]; then
echo -e "Test files don't contain a test environment configuration:"
Expand Down

0 comments on commit 2290935

Please sign in to comment.