From 20062b11b998a0d7c52bb3f5bee679cc6fc5f940 Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Sun, 5 Sep 2021 10:04:44 -0700 Subject: [PATCH] Add test for static/dynamic RAM check --- cypress.json | 1 + cypress/integration/netscript.spec.ts | 65 ++++++++++++++++++--------- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/cypress.json b/cypress.json index 0a76aaaee..52a751f84 100644 --- a/cypress.json +++ b/cypress.json @@ -1,5 +1,6 @@ { "baseUrl": "http://localhost:8000", + "fixturesFolder": false, "trashAssetsBeforeRuns": true, "screenshotsFolder": ".cypress/screenshots", "videosFolder": ".cypress/videos", diff --git a/cypress/integration/netscript.spec.ts b/cypress/integration/netscript.spec.ts index 46c310d79..b4afb03a8 100644 --- a/cypress/integration/netscript.spec.ts +++ b/cypress/integration/netscript.spec.ts @@ -1,32 +1,55 @@ export {}; -it("creates and runs a NetScript 2.0 script", () => { - cy.findByRole("button", { name: "Exit Tutorial" }).click(); - cy.findByText("Got it!").click(); +describe("netscript", () => { + it("creates and runs a NetScript 2.0 script", () => { + cy.findByRole("button", { name: "Exit Tutorial" }).click(); + cy.findByText("Got it!").click(); - cy.findByRole("textbox").type("connect n00dles{enter}"); - cy.findByText(/connected to n00dles/i); + cy.findByRole("textbox").type("connect n00dles{enter}"); + cy.findByText(/connected to n00dles/i); - cy.findByRole("textbox").type("run NUKE.exe{enter}"); - cy.findByText(/gained root access/i); + cy.findByRole("textbox").type("run NUKE.exe{enter}"); + cy.findByText(/gained root access/i); - cy.findByRole("textbox").type("home{enter}"); - cy.findByText(/connected to home/i); + cy.findByRole("textbox").type("home{enter}"); + cy.findByText(/connected to home/i); - cy.findByRole("textbox").type("nano script.js{enter}"); + cy.findByRole("textbox").type("nano script.js{enter}"); - // monaco can take a bit - cy.findByRole("code", { timeout: 15_000 }).type("{selectall}{del}") - .type(`export const main = async (ns) => {{} -while(true) {{} -await ns.hack("n00dles");`); + // monaco can take a bit + cy.findByRole("code", { timeout: 15_000 }).type("{selectall}{del}") + .type(`export const main = async (ns) => {{} + while(true) {{} + await ns.hack("n00dles");`); - cy.findByText("RAM: 1.70GB"); - cy.findByRole("button", { name: /Save & Close/i }).click(); + cy.findByText("RAM: 1.70GB"); + cy.findByRole("button", { name: /Save & Close/i }).click(); - cy.findByRole("textbox").type("run script.js{enter}"); - cy.findByText(/Running script with 1 thread/); + cy.findByRole("textbox").type("run script.js{enter}"); + cy.findByText(/Running script with 1 thread/); - cy.findByRole("textbox").type("ps{enter}"); - cy.findByText(/\(PID - 1\) script.js/); + cy.findByRole("textbox").type("ps{enter}"); + cy.findByText(/\(PID - 1\) script.js/); + }); + + it("errors and shows a dialog box when static RAM !== dynamic RAM", () => { + cy.findByRole("button", { name: "Exit Tutorial" }).click(); + cy.findByText("Got it!").click(); + + cy.findByRole("textbox").type("nano script.js{enter}"); + + // monaco can take a bit + cy.findByRole("code", { timeout: 15_000 }).type("{selectall}{del}") + .type(`export const main = async (ns) => {{} +const command = "hack"; +ns[command]("n00dles");`); + + cy.findByText("RAM: 1.60GB"); + cy.findByRole("button", { name: /Save & Close/i }).click(); + + cy.findByRole("textbox").type("run script.js{enter}"); + cy.findByText( + /Dynamic RAM usage calculated to be greater than initial RAM usage on fn: hack./i, + ); + }); });