diff --git a/.changeset/metal-jokes-judge.md b/.changeset/metal-jokes-judge.md new file mode 100644 index 0000000000..eb3bb7723e --- /dev/null +++ b/.changeset/metal-jokes-judge.md @@ -0,0 +1,5 @@ +--- +"create-fuels": patch +--- + +chore: add integration test for `create fuels` diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0ae69ce7a1..b81563cbf5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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 @@ -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 @@ -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' diff --git a/package.json b/package.json index c33b346b6e..80c9589f5f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/create-fuels/src/cli.ts b/packages/create-fuels/src/cli.ts index ca3b524b10..9d4deff828 100644 --- a/packages/create-fuels/src/cli.ts +++ b/packages/create-fuels/src/cli.ts @@ -126,6 +126,7 @@ export const runScaffoldCli = async ({ process.chdir(projectPath); execSync(packageManager.install, { stdio: verboseEnabled ? 'inherit' : 'pipe' }); + installDepsSpinner.succeed('Installed dependencies!'); } diff --git a/packages/create-fuels/src/lib/setupProgram.test.ts b/packages/create-fuels/src/lib/setupProgram.test.ts index 215edfa036..684b4afc4f 100644 --- a/packages/create-fuels/src/lib/setupProgram.test.ts +++ b/packages/create-fuels/src/lib/setupProgram.test.ts @@ -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', () => { diff --git a/packages/create-fuels/test/e2e.test.ts b/packages/create-fuels/test/integration.test.ts similarity index 98% rename from packages/create-fuels/test/e2e.test.ts rename to packages/create-fuels/test/integration.test.ts index a2350ac7df..41e236b98e 100644 --- a/packages/create-fuels/test/e2e.test.ts +++ b/packages/create-fuels/test/integration.test.ts @@ -23,7 +23,7 @@ const packageManagerCreateCommands: [PackageManager, string][] = [ ]; /** - * @group e2e + * @group integration */ describe('`create fuels` package integrity', () => { let paths: ProjectPaths; diff --git a/scripts/create-fuels-template-integration.sh b/scripts/create-fuels-template-integration.sh deleted file mode 100644 index 5f9fd52e6b..0000000000 --- a/scripts/create-fuels-template-integration.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -(cd templates/nextjs && pnpm run fuels:dev) & -cp templates/nextjs/.env.example templates/nextjs/.env.local -(cd templates/nextjs && pnpm run dev) & -pnpm exec playwright install --with-deps -pnpm exec playwright test \ No newline at end of file diff --git a/scripts/tests-find.sh b/scripts/tests-find.sh index 74e258411b..fb83e6e31e 100755 --- a/scripts/tests-find.sh +++ b/scripts/tests-find.sh @@ -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 diff --git a/scripts/tests-ui-integration.sh b/scripts/tests-ui-integration.sh new file mode 100755 index 0000000000..33e94106db --- /dev/null +++ b/scripts/tests-ui-integration.sh @@ -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 diff --git a/scripts/tests-ui.sh b/scripts/tests-ui.sh new file mode 100644 index 0000000000..d5059a2539 --- /dev/null +++ b/scripts/tests-ui.sh @@ -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 \ No newline at end of file diff --git a/scripts/tests-validate.sh b/scripts/tests-validate.sh index 74917d2fb8..bb665beba1 100755 --- a/scripts/tests-validate.sh +++ b/scripts/tests-validate.sh @@ -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:"