-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from classmodel/test-node-playwright
Replace jest with test:node + add playwright
- Loading branch information
Showing
13 changed files
with
293 additions
and
1,796 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
unittest: | ||
name: Unit tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v4 | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20" | ||
cache: "pnpm" | ||
cache-dependency-path: ./pnpm-lock.yaml | ||
- name: Install dependencies | ||
run: pnpm install | ||
- name: Test | ||
run: pnpm test | ||
e2etest: | ||
name: end-to-end tests | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v4 | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20" | ||
cache: "pnpm" | ||
cache-dependency-path: ./pnpm-lock.yaml | ||
- name: Install dependencies | ||
run: pnpm install | ||
- name: Install Playwright Browsers | ||
run: pnpm exec playwright install --with-deps chromium | ||
working-directory: ./apps/class-solid | ||
- name: Run Playwright tests | ||
run: pnpm exec playwright test | ||
working-directory: ./apps/class-solid | ||
- uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: apps/class-solid/playwright-report/ | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// import dotenv from 'dotenv'; | ||
// dotenv.config({ path: path.resolve(__dirname, '.env') }); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: "./tests", | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: "html", | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
baseURL: "http://localhost:3000", | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: "on-first-retry", | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
|
||
// { | ||
// name: 'firefox', | ||
// use: { ...devices['Desktop Firefox'] }, | ||
// }, | ||
|
||
// { | ||
// name: 'webkit', | ||
// use: { ...devices['Desktop Safari'] }, | ||
// }, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: "pnpm dev", | ||
cwd: "../..", | ||
url: "http://localhost:3000", | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
test("has welcome", async ({ page }) => { | ||
await page.goto("/"); | ||
|
||
await expect( | ||
page.getByRole("heading", { name: "Welcome to CLASS" }), | ||
).toBeVisible(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lcov.info | ||
coverage/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import assert from "node:assert/strict"; | ||
import { before, describe, test } from "node:test"; | ||
import { BmiClass } from "./bmi"; | ||
|
||
describe("BmiClass", () => { | ||
let bmi: BmiClass; | ||
before(() => { | ||
bmi = new BmiClass(); | ||
}); | ||
|
||
describe("get_component_name", () => { | ||
test("returns the component name", () => { | ||
assert.strictEqual( | ||
bmi.get_component_name(), | ||
"Chemistry Land-surface Atmosphere Soil Slab model", | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,42 @@ | ||
import assert from "node:assert/strict"; | ||
import { describe, test } from "node:test"; | ||
|
||
import { CLASS } from "./class"; | ||
import { classConfig } from "./config"; | ||
import { runClass } from "./runner"; | ||
|
||
describe("CLASS model", () => { | ||
it("can be instantiated with default config", () => { | ||
test("can be instantiated with default config", () => { | ||
const config = classConfig.parse({}); | ||
const model = new CLASS(config); | ||
expect(model).toBeInstanceOf(CLASS); | ||
expect(model.t).toEqual(0); | ||
expect(model._cfg.initialState.h_0).toEqual(200); | ||
expect(model._cfg.timeControl.dt).toEqual(60); | ||
expect(model._cfg.mixedLayer.wtheta).toEqual(0.1); | ||
expect(model._cfg.mixedLayer.wq).toEqual(0.0001); | ||
assert.ok(model instanceof CLASS); | ||
assert.strictEqual(model.t, 0); | ||
assert.strictEqual(model._cfg.initialState.h_0, 200); | ||
assert.strictEqual(model._cfg.timeControl.dt, 60); | ||
assert.strictEqual(model._cfg.mixedLayer.wtheta, 0.1); | ||
assert.strictEqual(model._cfg.mixedLayer.wq, 0.0001); | ||
}); | ||
|
||
test("calling update advances the model time", () => { | ||
const config = classConfig.parse({}); | ||
const model = new CLASS(config); | ||
model.update(); | ||
expect(model.t).toEqual(60); | ||
assert.strictEqual(model.t, 60); | ||
}); | ||
|
||
it("can update until the final time step", () => { | ||
test("can update until the final time step", () => { | ||
const config = classConfig.parse({}); | ||
const model = new CLASS(config); | ||
while (model.t < config.timeControl.runtime) { | ||
model.update(); | ||
} | ||
expect(model.t).toEqual(12 * 3600); | ||
assert.strictEqual(model.t, 12 * 3600); | ||
}); | ||
|
||
it("produces realistic results", () => { | ||
test("produces realistic results", () => { | ||
const config = classConfig.parse({}); | ||
const output = runClass(config); | ||
console.log(output); | ||
expect(output); | ||
assert.ok(output); | ||
}); | ||
}); |
Oops, something went wrong.