Skip to content

Commit dd667f1

Browse files
committed
Run eslint on our cypress tests
My editor was reformatting them by default, rather than configure the settings of my eslint extension, I thought we should apply the same linting rules the tests as our other code.
1 parent c2aa19e commit dd667f1

7 files changed

Lines changed: 60 additions & 56 deletions

File tree

.eslintrc.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,14 @@
4343
"arrowParens": "always"
4444
}
4545
]
46-
}
46+
},
47+
"overrides": [
48+
{
49+
"files": ["cypress/**/*.js"],
50+
"globals": {
51+
"cy": "readonly",
52+
"Cypress": "readonly"
53+
}
54+
}
55+
]
4756
}

cypress/e2e/missionZero-wc.cy.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ it("sets initial criteria correctly", () => {
3838
cy.get("editor-wc").shadow().find(".btn--run").click();
3939
cy.get("#results").should(
4040
"contain",
41-
'"noInputEvents":true,"readColour":false,"readHumidity":false,"readPressure":false,"readTemperature":false,"usedLEDs":false'
41+
'"noInputEvents":true,"readColour":false,"readHumidity":false,"readPressure":false,"readTemperature":false,"usedLEDs":false',
4242
);
4343
});
4444

@@ -57,7 +57,7 @@ it("checks temperature has been read correctly", () => {
5757
.find("div[class=cm-content]")
5858
.invoke(
5959
"text",
60-
"from sense_hat import SenseHat\nSenseHat().get_temperature()"
60+
"from sense_hat import SenseHat\nSenseHat().get_temperature()",
6161
);
6262
cy.get("editor-wc").shadow().find(".btn--run").click();
6363
cy.get("#results").should("contain", '"readTemperature":true');
@@ -69,7 +69,7 @@ it("checks humidity has been read correctly", () => {
6969
.find("div[class=cm-content]")
7070
.invoke(
7171
"text",
72-
"from sense_hat import SenseHat\nSenseHat().get_humidity()"
72+
"from sense_hat import SenseHat\nSenseHat().get_humidity()",
7373
);
7474
cy.get("editor-wc").shadow().find(".btn--run").click();
7575
cy.get("#results").should("contain", '"readHumidity":true');
@@ -81,7 +81,7 @@ it("checks pressure has been read correctly", () => {
8181
.find("div[class=cm-content]")
8282
.invoke(
8383
"text",
84-
"from sense_hat import SenseHat\nSenseHat().get_pressure()"
84+
"from sense_hat import SenseHat\nSenseHat().get_pressure()",
8585
);
8686
cy.get("editor-wc").shadow().find(".btn--run").click();
8787
cy.get("#results").should("contain", '"readPressure":true');
@@ -93,7 +93,7 @@ it("resets criteria correctly", () => {
9393
.find("div[class=cm-content]")
9494
.invoke(
9595
"text",
96-
"from sense_hat import SenseHat\nsense = SenseHat()\nsense.get_pressure()\nsense.get_humidity()\nsense.get_temperature()"
96+
"from sense_hat import SenseHat\nsense = SenseHat()\nsense.get_pressure()\nsense.get_humidity()\nsense.get_temperature()",
9797
);
9898
cy.get("editor-wc").shadow().find(".btn--run").contains("Run").click();
9999
cy.get("#results").should("contain", '"readPressure":true');
@@ -104,7 +104,7 @@ it("resets criteria correctly", () => {
104104
cy.get("editor-wc").shadow().find(".btn--run").contains("Run").click();
105105
cy.get("#results").should(
106106
"contain",
107-
'"noInputEvents":true,"readColour":false,"readHumidity":false,"readPressure":false,"readTemperature":false,"usedLEDs":false'
107+
'"noInputEvents":true,"readColour":false,"readHumidity":false,"readPressure":false,"readTemperature":false,"usedLEDs":false',
108108
);
109109
});
110110

@@ -114,7 +114,7 @@ it("confirms LEDs used when single led set", () => {
114114
.find("div[class=cm-content]")
115115
.invoke(
116116
"text",
117-
"from sense_hat import SenseHat\nSenseHat().set_pixel(0, 0, 100, 100, 100)"
117+
"from sense_hat import SenseHat\nSenseHat().set_pixel(0, 0, 100, 100, 100)",
118118
);
119119
cy.get("editor-wc").shadow().find(".btn--run").click();
120120
cy.get("#results").should("contain", '"usedLEDs":true');
@@ -126,7 +126,7 @@ it("confirms LEDs used when display set", () => {
126126
.find("div[class=cm-content]")
127127
.invoke(
128128
"text",
129-
"from sense_hat import SenseHat\nsense = SenseHat()\nsense.set_pixels([[100,0,0]] * 64)"
129+
"from sense_hat import SenseHat\nsense = SenseHat()\nsense.set_pixels([[100,0,0]] * 64)",
130130
);
131131
cy.get("editor-wc").shadow().find(".btn--run").click();
132132
cy.scrollTo("bottom");
@@ -162,7 +162,7 @@ it("picks up calls to wait for motion", () => {
162162
.find("div[class=cm-content]")
163163
.invoke(
164164
"text",
165-
"from sense_hat import SenseHat\nsense = SenseHat()\nsense.motion.wait_for_motion()"
165+
"from sense_hat import SenseHat\nsense = SenseHat()\nsense.motion.wait_for_motion()",
166166
);
167167
cy.get("editor-wc").shadow().find(".btn--run").click();
168168
cy.get("#results").should("contain", '"noInputEvents":false');
@@ -183,7 +183,7 @@ it("does not return null duration if no change in focus", () => {
183183
.find("div[class=cm-content]")
184184
.invoke(
185185
"text",
186-
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")'
186+
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")',
187187
);
188188
cy.get("editor-wc").shadow().find(".btn--run").click();
189189
cy.get("#results").should("not.contain", '"duration":null');
@@ -195,7 +195,7 @@ it("does not return null duration if focus changed before code run", () => {
195195
.find("div[class=cm-content]")
196196
.invoke(
197197
"text",
198-
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")'
198+
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")',
199199
);
200200
cy.window().blur();
201201
cy.window().focus();
@@ -209,7 +209,7 @@ it("returns duration of null if focus is lost", () => {
209209
.find("div[class=cm-content]")
210210
.invoke(
211211
"text",
212-
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")'
212+
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")',
213213
);
214214
cy.get("editor-wc")
215215
.shadow()
@@ -228,7 +228,7 @@ it("does not return duration of null if code rerun after focus lost", () => {
228228
.find("div[class=cm-content]")
229229
.invoke(
230230
"text",
231-
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")'
231+
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")',
232232
);
233233
cy.get("editor-wc").shadow().find(".btn--run").click();
234234
cy.window().blur();

cypress/e2e/spec-html.cy.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ beforeEach(() => {
3636
cy.intercept(
3737
"GET",
3838
`${Cypress.env(
39-
"REACT_APP_API_ENDPOINT"
39+
"REACT_APP_API_ENDPOINT",
4040
)}/api/projects/blank-html-starter?locale=en`,
41-
defaultHtmlProject
41+
defaultHtmlProject,
4242
);
4343
});
4444

@@ -55,7 +55,7 @@ it("blocks access to localStorage authKey", () => {
5555
localStorage.setItem("authKey", "secret")
5656
const authKey = localStorage.getItem("authKey")
5757
document.getElementById("authKey").innerHTML = \`\${authKey}\`
58-
</script>`
58+
</script>`,
5959
);
6060
cy.get("editor-wc").shadow().find(".btn--run").click();
6161
getIframeBody().find("p").should("include.text", "authKey: null");
@@ -74,7 +74,7 @@ it("blocks access to localStorage OIDC keys", () => {
7474
localStorage.setItem("oidc.user:https://auth-v1.raspberrypi.org:editor-api", "token")
7575
const oidcUser = localStorage.getItem("oidc.user:https://auth-v1.raspberrypi.org:editor-api")
7676
document.getElementById("oidcUser").innerHTML = \`\${oidcUser}\`
77-
</script>`
77+
</script>`,
7878
);
7979
cy.get("editor-wc").shadow().find(".btn--run").click();
8080
getIframeBody().find("p").should("include.text", "oidcUser: null");
@@ -93,7 +93,7 @@ it("allows access to other localStorage keys", () => {
9393
localStorage.setItem("foo", "bar")
9494
const foo = localStorage.getItem("foo")
9595
document.getElementById("foo").innerHTML = \`\${foo}\`
96-
</script>`
96+
</script>`,
9797
);
9898
cy.get("editor-wc").shadow().find(".btn--run").click();
9999
getIframeBody().find("p").should("include.text", "foo: bar");
@@ -138,7 +138,7 @@ it("blocks non-permitted external links", () => {
138138
.find("div[class=cm-content]")
139139
.invoke(
140140
"text",
141-
'<a href="https://raspberrypi.org/en/">some external link</a>'
141+
'<a href="https://raspberrypi.org/en/">some external link</a>',
142142
);
143143
cy.get("editor-wc").shadow().find(".btn--run").click();
144144
getIframeBody().find("a").click();

cypress/e2e/spec-wc-pyodide.cy.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -154,76 +154,71 @@ describe("Running the code with pyodide", () => {
154154

155155
it("runs a program with muiltiple files", () => {
156156
cy.get("@editor")
157-
.findByLabelText('editor text input')
157+
.findByLabelText("editor text input")
158158
.invoke("text", `from my_number import NUMBER\nprint(NUMBER)\n`);
159159

160-
cy.get("@editor").findByRole('button', { name: 'Add file' }).click()
160+
cy.get("@editor").findByRole("button", { name: "Add file" }).click();
161161

162162
cy.get("@editor")
163163
.findByLabelText(/Name your file/)
164164
.type("my_number.py");
165165

166166
cy.get("@editor")
167-
.findByRole('dialog')
168-
.findByRole('button', { name: 'Add file' }).click()
167+
.findByRole("dialog")
168+
.findByRole("button", { name: "Add file" })
169+
.click();
169170

170171
cy.get("@editor")
171-
.findByLabelText('editor text input')
172+
.findByLabelText("editor text input")
172173
.invoke("text", `NUMBER = 42\n`);
173174

174-
cy.get("@editor")
175-
.findByRole('button', { name: 'Run' }).click();
175+
cy.get("@editor").findByRole("button", { name: "Run" }).click();
176176

177177
cy.get("@editor")
178178
.find(".pyodiderunner")
179-
.findByLabelText('Text output')
179+
.findByLabelText("Text output")
180180
.should("contain", "42");
181181
});
182182

183-
184183
it("reloads imported local files between code runs", () => {
185184
cy.get("@editor")
186-
.findByLabelText('editor text input')
187-
.invoke("text",
188-
`from helper import b\nb()`
189-
);
185+
.findByLabelText("editor text input")
186+
.invoke("text", `from helper import b\nb()`);
190187

191-
cy.get("@editor").findByRole('button', { name: 'Add file' }).click()
188+
cy.get("@editor").findByRole("button", { name: "Add file" }).click();
192189

193190
cy.get("@editor")
194191
.findByLabelText(/Name your file/)
195192
.type("helper.py");
196193

197194
cy.get("@editor")
198-
.findByRole('dialog')
199-
.findByRole('button', { name: 'Add file' }).click()
195+
.findByRole("dialog")
196+
.findByRole("button", { name: "Add file" })
197+
.click();
200198

201199
cy.get("@editor")
202-
.findByLabelText('editor text input')
200+
.findByLabelText("editor text input")
203201
.invoke("text", `def b():\n print('one')`);
204202

205-
cy.get("@editor")
206-
.findByRole('button', { name: 'Run' }).click();
203+
cy.get("@editor").findByRole("button", { name: "Run" }).click();
207204

208205
cy.get("@editor")
209206
.find(".pyodiderunner")
210-
.findByLabelText('Text output')
207+
.findByLabelText("Text output")
211208
.should("contain", "one");
212-
209+
213210
cy.get("@editor")
214-
.findByLabelText('editor text input')
211+
.findByLabelText("editor text input")
215212
.invoke("text", `def b():\n print('two')`);
216213

217-
cy.get("@editor")
218-
.findByRole('button', { name: 'Run' }).click();
214+
cy.get("@editor").findByRole("button", { name: "Run" }).click();
219215

220216
cy.get("@editor")
221217
.find(".pyodiderunner")
222-
.findByLabelText('Text output')
218+
.findByLabelText("Text output")
223219
.should("contain", "two");
224220
});
225221

226-
227222
it("runs a simple program with a built-in pyodide module", () => {
228223
runCode(
229224
"import simplejson as json\nprint(json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}]))",

cypress/e2e/spec-wc-skulpt.cy.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe("Running the code with skulpt", () => {
5252

5353
it("runs a simple p5 program", () => {
5454
runCode(
55-
"from p5 import *\n\ndef setup():\n\tsize(400, 400)\ndef draw():\n\tfill('cyan')\n\trect(0, 0, 400, 250)\nrun(frame_rate=2)"
55+
"from p5 import *\n\ndef setup():\n\tsize(400, 400)\ndef draw():\n\tfill('cyan')\n\trect(0, 0, 400, 250)\nrun(frame_rate=2)",
5656
);
5757
cy.get("editor-wc")
5858
.shadow()
@@ -69,14 +69,14 @@ describe("Running the code with skulpt", () => {
6969

7070
it("runs a simple py5 program", () => {
7171
runCode(
72-
"import py5\ndef setup():\n\tpy5.size(400, 400)\ndef draw():\n\tpy5.background(255)\npy5.run_sketch()"
72+
"import py5\ndef setup():\n\tpy5.size(400, 400)\ndef draw():\n\tpy5.background(255)\npy5.run_sketch()",
7373
);
7474
cy.get("editor-wc").shadow().find(".p5Canvas").should("exist");
7575
});
7676

7777
it("Interrupts py5 draws when stop button clicked", () => {
7878
runCode(
79-
"import py5\ndef setup():\n\tpy5.size(400, 400)\ndef draw():\n\tpy5.background(255)\npy5.run_sketch()"
79+
"import py5\ndef setup():\n\tpy5.size(400, 400)\ndef draw():\n\tpy5.background(255)\npy5.run_sketch()",
8080
);
8181
cy.wait(1000);
8282
cy.get("editor-wc").shadow().find(".btn--stop").click();
@@ -93,7 +93,7 @@ describe("Running the code with skulpt", () => {
9393

9494
it("Py5 imported mode runs sketch without explicit run call", () => {
9595
runCode(
96-
"# Py5: imported mode\ndef setup():\n\tsize(400,400)\n\ndef draw():\n\tprint('hello world')"
96+
"# Py5: imported mode\ndef setup():\n\tsize(400,400)\n\ndef draw():\n\tprint('hello world')",
9797
);
9898
cy.get("editor-wc")
9999
.shadow()
@@ -103,7 +103,7 @@ describe("Running the code with skulpt", () => {
103103

104104
it("runs a simple sense_hat program", () => {
105105
runCode(
106-
"from sense_hat import SenseHat\nsense = SenseHat()\nprint(sense.get_humidity())"
106+
"from sense_hat import SenseHat\nsense = SenseHat()\nprint(sense.get_humidity())",
107107
);
108108
cy.get("editor-wc")
109109
.shadow()
@@ -150,7 +150,7 @@ describe("Running the code with skulpt", () => {
150150

151151
it("runs a simple turtle program", () => {
152152
runCode(
153-
"import turtle\nskk = turtle.Turtle()\nfor i in range(4):\n\tskk.forward(50)\n\tskk.left(90)\nturtle.done()"
153+
"import turtle\nskk = turtle.Turtle()\nfor i in range(4):\n\tskk.forward(50)\n\tskk.left(90)\nturtle.done()",
154154
);
155155
cy.get("editor-wc")
156156
.shadow()
@@ -172,7 +172,7 @@ describe("Running the code with skulpt", () => {
172172
.find(".error-message__content")
173173
.should(
174174
"contain.text",
175-
"ImportError: No module named matplotlib on line 2 of main.py. You should check your code for typos. If you are using p5, py5, sense_hat or turtle, matplotlib might not work - read this article for more information."
175+
"ImportError: No module named matplotlib on line 2 of main.py. You should check your code for typos. If you are using p5, py5, sense_hat or turtle, matplotlib might not work - read this article for more information.",
176176
);
177177
});
178178
});

cypress/support/e2e.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import '@testing-library/cypress/add-commands'
1+
import "@testing-library/cypress/add-commands";

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
"build": "NODE_ENV=production BABEL_ENV=production webpack build -c ./webpack.config.js",
9090
"build:dev": "yarn install --check-cache && yarn run build-storybook",
9191
"build-storybook": "cd ./storybook && yarn install && yarn run build-storybook -- -o ../public/storybook --loglevel warn",
92-
"lint": "eslint \"src/**/*.{js,jsx,json}\"",
93-
"lint:fix": "eslint --fix \"src/**/*.{js,jsx,json}\"",
92+
"lint": "eslint 'src/**/*.{js,jsx,json}' cypress/**/*.js",
93+
"lint:fix": "eslint --fix 'src/**/*.{js,jsx,json}' cypress/**/*.js",
9494
"stylelint": "stylelint src/**/*.scss",
9595
"test": "node scripts/test.js --transformIgnorePatterns 'node_modules/(?!three)/'",
9696
"storybook": "cd storybook && rm -rf ./node_modules/.cache/storybook && yarn run storybook",

0 commit comments

Comments
 (0)