Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add vitest update #445

Merged
merged 17 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/cuddly-planets-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@moonwall/types": patch
"@moonwall/cli": patch
"@moonwall/docs": patch
"@moonwall/tests": patch
---

Add snapshot update option
10 changes: 5 additions & 5 deletions .changeset/lucky-boats-cheat.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
"@moonwall/types": major
"@moonwall/cli": major
"@moonwall/tests": major
"@moonwall/docs": major
"@moonwall/util": major
"@moonwall/types": minor
"@moonwall/cli": minor
"@moonwall/tests": minor
"@moonwall/docs": minor
"@moonwall/util": minor
---

Added Fork config to dev foundations
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,46 @@ jobs:
bun papi generate
bun moonwall test ${{matrix.suite}} --ts ${{ matrix.shard }}/4

test_update:
runs-on: ubuntu-latest
needs: ["build"]
env:
NO_COLOR: 1
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- uses: pnpm/action-setup@v4
with:
version: 9.1.4
- uses: actions/setup-node@v4
with:
node-version: 23
cache: "pnpm"
- name: Build like before
run: |
pnpm install
pnpm run build
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Run snapshot update test
id: update_test
run: |
cd test
bun moonwall test update_snapshot -u > snapshot_output.txt 2>&1
- name: Check if files were modified in the 2 minutes
run: |
cd test
find suites/update/__snapshots__/test_basic.ts.snap suites/update/timbo.txt
find suites/update/__snapshots__/test_basic.ts.snap suites/update/timbo.txt -mmin -2 | wc -l | grep -q "2"
- name: Check console output for snapshot updates
run: |
cd test
cat snapshot_output.txt
grep "Snapshots 3 updated" snapshot_output.txt

test_chopsticks:
runs-on: ubuntu-latest
needs: ["build"]
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/cmds/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ yargs(hideBin(process.argv))
describe: "Test Shard info for CI",
alias: "ts",
type: "string",
})
.option("update", {
describe: "Update all snapshots",
alias: "u",
type: "boolean",
});
},
async (args) => {
Expand All @@ -100,6 +105,7 @@ yargs(hideBin(process.argv))
testNamePattern: args.GrepTest,
subDirectory: args.subDirectory,
shard: args.testShard,
update: args.update,
}))
) {
process.exitCode = 1;
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/cmds/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type testRunArgs = {
testNamePattern?: string;
subDirectory?: string;
shard?: string;
update?: boolean;
};

export async function executeTests(env: Environment, testRunArgs?: testRunArgs) {
Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ cache
artifacts
**/tmp/*
**/contracts/out/
snapshot_output.txt
11 changes: 11 additions & 0 deletions test/moonwall.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@
]
}
},
{
"name": "update_snapshot",
"testFileDir": ["suites/update"],
"foundation": {
"type": "read_only",
"launchSpec": {
"disableRuntimeVersionCheck": true
}
},
"connections": []
},
{
"name": "failing_prescript",
"testFileDir": ["suites/basic"],
Expand Down
7 changes: 5 additions & 2 deletions test/suites/fork_test/test_fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describeSuite({
forkConfig: {
url: "https://moonbeam.unitedbloc.com",
verbose: true,
blockHash: "0xffe39256c17cc4523a07c907bcf1aeeef4db217cd57cfcfb95d56088e0bb9f2d"
blockHash: "0xffe39256c17cc4523a07c907bcf1aeeef4db217cd57cfcfb95d56088e0bb9f2d",
},
},
testCases: ({ it, context, log }) => {
Expand Down Expand Up @@ -55,7 +55,10 @@ describeSuite({
const {
data: { free },
} = await polkadotJs.query.system.account(testAccount);
expect(free.toBigInt(), `Free balance should match what account ${testAccount} has at block #8508372`).toBe(76562560590695097485140n);
expect(
free.toBigInt(),
`Free balance should match what account ${testAccount} has at block #8508372`
).toBe(76562560590695097485140n);
},
});
},
Expand Down
3 changes: 3 additions & 0 deletions test/suites/update/__snapshots__/test_basic.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`🗃️ U01 This is a test suite that tests the update snapshot feature > 📁 U01T02 Normal snapshot 1`] = `7`;
40 changes: 40 additions & 0 deletions test/suites/update/test_basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { expect, describeSuite, beforeAll } from "@moonwall/cli";

describeSuite({
id: "U01",
title: "This is a test suite that tests the update snapshot feature",
foundationMethods: "read_only",
testCases: ({ it, log }) => {
let random: number;

beforeAll(() => {
random = Math.floor(Math.random() * 100);
log(`The random number is ${random}`);
});

it({
id: "T01",
title: "In-line snapshot",
test: () => {
// biome-ignore lint/style/noUnusedTemplateLiteral: <explanation>
expect(random).toMatchInlineSnapshot(`7`);
},
});

it({
id: "T02",
title: "Normal snapshot",
test: () => {
expect(random).toMatchSnapshot();
},
});

it({
id: "T03",
title: "File snapshot",
test: () => {
expect(random).toMatchFileSnapshot("./timbo.txt");
},
});
},
});
1 change: 1 addition & 0 deletions test/suites/update/timbo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7