mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-03-27 16:25:43 +02:00
tests: hello world playground run with success and failure tests (#2513)
Implement two tests for the rust playground: - successful run of the hello world example with the hello world message in stdout and a hidden stderr - on purpose compilation error is shown in stderr and "No output" in stdout
This commit is contained in:
parent
7584ce0048
commit
34920c76e6
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@ -189,6 +189,7 @@ jobs:
|
||||
run: npm install
|
||||
working-directory: ./tests
|
||||
- name: Test Javascript
|
||||
if: matrix.language == 'en'
|
||||
run: npm test
|
||||
env:
|
||||
TEST_BOOK_DIR: ../book/comprehensive-rust-${{ matrix.language }}/html
|
||||
|
1204
tests/package-lock.json
generated
1204
tests/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -3,10 +3,10 @@
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.10",
|
||||
"@wdio/cli": "^9.3.0",
|
||||
"@wdio/local-runner": "^9.3.0",
|
||||
"@wdio/mocha-framework": "^9.2.8",
|
||||
"@wdio/static-server-service": "^9.2.2"
|
||||
"@wdio/cli": "^9.5.3",
|
||||
"@wdio/local-runner": "^9.5.3",
|
||||
"@wdio/mocha-framework": "^9.5.0",
|
||||
"@wdio/static-server-service": "^9.5.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "npm run test",
|
||||
|
59
tests/src/playground.test.ts
Normal file
59
tests/src/playground.test.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import { describe, it } from "mocha";
|
||||
import { $, expect, browser } from "@wdio/globals";
|
||||
import { Key } from "webdriverio";
|
||||
|
||||
describe("Playground", () => {
|
||||
it("executes the hello world code and prints the hello message", async () => {
|
||||
await browser.url("/hello-world/hello-world.html");
|
||||
const playground_area = $(".ace_content");
|
||||
const playground_start_button = $("button.play-button");
|
||||
const playground_stderr = $("code.result.stderr");
|
||||
const playground_stdout = $("code.result.stdout");
|
||||
|
||||
// ensure a playground exists and pre-state is as expected
|
||||
await expect(playground_area).toExist();
|
||||
await expect(playground_start_button).toExist();
|
||||
await expect(playground_start_button).not.toBeDisplayed();
|
||||
await expect(playground_stderr).not.toExist();
|
||||
await expect(playground_stdout).not.toExist();
|
||||
|
||||
// clicking into the content is necessary for the button to be displayed
|
||||
await playground_area.waitForClickable();
|
||||
await playground_area.click();
|
||||
await expect(playground_start_button).toBeDisplayed();
|
||||
|
||||
// clicking the button triggers action
|
||||
await playground_start_button.waitForClickable();
|
||||
await playground_start_button.click();
|
||||
await expect(playground_stdout).toBeDisplayed();
|
||||
await expect(playground_stderr).not.toBeDisplayed();
|
||||
await expect(playground_stdout).toHaveText(expect.stringContaining("🌍"));
|
||||
});
|
||||
|
||||
it("shows error messages in stderr if the code is broken", async () => {
|
||||
await browser.url("/hello-world/hello-world.html");
|
||||
const playground_area = $(".ace_content");
|
||||
const playground_start_button = $("button.play-button");
|
||||
const playground_stderr = $("code.result.stderr");
|
||||
const playground_stdout = $("code.result.stdout");
|
||||
|
||||
// clicking into the content is necessary for the button to be displayed
|
||||
await playground_area.waitForClickable();
|
||||
await playground_area.click();
|
||||
|
||||
// append some failing code to the editor that is now in focus
|
||||
await browser.keys([Key.Enter, "fn expect_failure()"]);
|
||||
|
||||
// clicking the button triggers action
|
||||
await playground_start_button.waitForClickable();
|
||||
await playground_start_button.click();
|
||||
await expect(playground_stdout).toBeDisplayed();
|
||||
await expect(playground_stderr).toBeDisplayed();
|
||||
|
||||
// check for error message in stderr
|
||||
await expect(playground_stderr).toHaveText(
|
||||
expect.stringContaining("error: could not compile")
|
||||
);
|
||||
await expect(playground_stdout).toHaveText("No output");
|
||||
});
|
||||
});
|
@ -201,8 +201,9 @@ export const config: WebdriverIO.Config = {
|
||||
* @param {Array.<String>} specs List of spec file paths that are to be run
|
||||
* @param {object} browser instance of created browser/device session
|
||||
*/
|
||||
// before: function (capabilities, specs) {
|
||||
// },
|
||||
before: function (capabilities, specs) {
|
||||
browser.setWindowSize(2560, 1440);
|
||||
},
|
||||
/**
|
||||
* Runs before a WebdriverIO command gets executed.
|
||||
* @param {string} commandName hook command name
|
||||
|
Loading…
x
Reference in New Issue
Block a user