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

Mipsy Web playwright testing #294

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test_files -linguist-detectable
test_files -linguist-detectable
4 changes: 4 additions & 0 deletions crates/mipsy_web/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.yarn/** linguist-vendored
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated
13 changes: 13 additions & 0 deletions crates/mipsy_web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,16 @@ dist/
tailwind.css
Session.vim
_static/tailwind.css
node_modules/
# Playwright
/test-results/
/playwright-report/
/playwright/.cache/
# Yarn v3 (Plug'n'Play) and Zero-Installs
.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
1 change: 1 addition & 0 deletions crates/mipsy_web/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.17.1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
874 changes: 874 additions & 0 deletions crates/mipsy_web/.yarn/releases/yarn-3.6.3.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions crates/mipsy_web/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.6.3.cjs
4 changes: 4 additions & 0 deletions crates/mipsy_web/Trunk.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public_url = "/"
# Whether to include hash values in the output file names.
filehash = true


[watch]
ignore = ["dist", "node_modules", "assets", "e2e_tests"]

[[hooks]]
stage = "build"
command = "sh"
Expand Down
18 changes: 18 additions & 0 deletions crates/mipsy_web/e2e_tests/home.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect } from '@playwright/test';

test('matches snapshot', async ({ page }) => {
await page.goto('http://localhost:8080/');

expect(await page.screenshot()).toMatchSnapshot('home.png');

});

test('get started link', async ({ page }) => {
await page.goto('/');

// Click the get started link.
await page.getByRole('link', { name: 'Get started' }).click();

// Expects page to have a heading with the name of Installation.
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions crates/mipsy_web/e2e_tests/output.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { test, expect } from '@playwright/test';

// a basic test that runs a file
// checks the output
// and checks that decompiled/data tabs are correct
test('basic_running', async ({ page }) => {
await page.goto('http://localhost:8080/');
await page.getByText('Load', { exact: true }).click();
await page.getByText('Load', { exact: true }).setInputFiles('../../../test_files/success/print10.s');
// file loaded correctly
// check editor has a main and a loop label
page.getByText('main:', { exact: true });
page.getByText('loop:', { exact: true });

// click the save button
await page.getByRole('button', { name: 'Save' }).click();
// wait for run button to be enabled
await page.waitForSelector('#run_button:not([disabled])');

// check decompiled tab contains 28 rows of instructions
await page.getByRole('button', { name: 'decompiled' }).click();
page.getByText('0x00400004 [0x34010005] ori $at, $zero, 5 ; [8] bge $s0, 5, end # if (i >= 5) goto end;', { exact: true });

// check data tab is empty
await page.getByRole('button', { name: 'data' }).click();
const data_output_div = page.locator('#data_output');
expect(await data_output_div.innerText()).toStrictEqual("");

// run the program
await page.getByRole('button', { name: 'Run' }).click();
const program_io_output = page.locator('#program_io_output').nth(0);

program_io_output.getByText('3\n9\n27\n81\n243', { exact: true });

});
64 changes: 64 additions & 0 deletions crates/mipsy_web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crates/mipsy_web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "mipsy_web",
"packageManager": "[email protected]",
"devDependencies": {
"@playwright/test": "^1.37.1"
}
}
72 changes: 72 additions & 0 deletions crates/mipsy_web/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './e2e_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://127.0.0.1:8080',

/* 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'] },
},

/* 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: 'trunk serve',
url: 'http://127.0.0.1:8080',
reuseExistingServer: !process.env.CI,
},
});
2 changes: 1 addition & 1 deletion crates/mipsy_web/src/components/data_segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn data_segment(props: &DataSegmentProps) -> Html {
let mut curr_segment = Segment::None;

html! {
<div id="output" style="min-width: 650px;margin-top: 10px;">
<div id="data_output" style="min-width: 650px;margin-top: 10px;">
<div style="width: 100%;">
{
for pages.into_iter().map(|(page_addr, page_contents)| {
Expand Down
2 changes: 1 addition & 1 deletion crates/mipsy_web/src/components/decompiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn render_decompiled(props: &DecompiledProps) -> Html {
let decompiled = &props.decompiled;
html! {
<pre class="text-xs">
<table>
<table id="decompiled_output">
{ html! {
for decompiled.as_str().split("\n").into_iter().map(|item| {
if item == "" {
Expand Down
3 changes: 2 additions & 1 deletion crates/mipsy_web/src/components/navbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,9 @@ pub fn render_navbar(props: &NavBarProps) -> Html {
item.title.clone()
};

let id_label = item.label.clone().to_lowercase().replace(" ", "_");
html! {
<button tabindex=0 {title} disabled={is_disabled} {onclick} class={button_classes}>
<button id={format!("{id_label}_button")} tabindex=0 {title} disabled={is_disabled} {onclick} class={button_classes}>
{ item.html.clone() }
{ item.label.clone() }
</button>
Expand Down
7 changes: 6 additions & 1 deletion crates/mipsy_web/src/components/outputarea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub fn render_output_area(props: &OutputProps) -> Html {
<div
style={if *props.show_io {"height: 80%;"} else {"height: 90%;"}}
class="py-2 w-full flex overflow-y-auto flex-wrap-reverse bg-th-secondary px-2 border-2 border-current"
id={if *props.show_io {"program_io_output"} else {"program_mipsy_output"}}
>
<div class="w-full overflow-y-auto">
<h1>
Expand All @@ -110,7 +111,11 @@ pub fn render_output_area(props: &OutputProps) -> Html {
</pre>
</div>
</div>
<div style="height: 10%;" class={if *props.show_io {"border-l-2 border-r-2 border-b-2 border-current"} else {"hidden"}}>
<div
style="height: 10%;"
class={if *props.show_io {"border-l-2 border-r-2 border-b-2 border-current"} else {"hidden"}}
id="user_input_container"
>
<input
ref={props.input_ref.clone()}
id="user_input"
Expand Down
Loading