Skip to content

Commit

Permalink
test: ES modules
Browse files Browse the repository at this point in the history
  • Loading branch information
felixerdy committed Dec 20, 2024
1 parent 59fb4ff commit 222047c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 61 deletions.
26 changes: 8 additions & 18 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
const chai = require("chai");
const chaiHttp = require("chai-http");
const server = require("../src/index");
const should = chai.should();

chai.use(chaiHttp);
import server from "../src/index.js";
import request from "./setup.js";

describe("Compiler", () => {
describe("/GET index", () => {
it("it should get the index page and answer with a 404 ", (done) => {
chai
.request(server)
request(server)
.get("/")
.end((err, res) => {
res.should.have.status(404);
Expand All @@ -20,8 +15,7 @@ describe("Compiler", () => {

describe("/compile", () => {
it("should reject request without board parameter", (done) => {
chai
.request(server)
request(server)
.post("/compile")
.send({ sketch: "void setup() {} void loop() {}" })
.end((err, res) => {
Expand All @@ -34,8 +28,7 @@ describe("Compiler", () => {
});

it("should reject request without sketch parameter", (done) => {
chai
.request(server)
request(server)
.post("/compile")
.send({ board: "sensebox-mcu" })
.end((err, res) => {
Expand All @@ -48,8 +41,7 @@ describe("Compiler", () => {
});

it("should reject request with invalid board", (done) => {
chai
.request(server)
request(server)
.post("/compile")
.send({
board: "esp8266",
Expand All @@ -67,8 +59,7 @@ describe("Compiler", () => {
});

it("should reject request with wrong Content-Type", (done) => {
chai
.request(server)
request(server)
.post("/compile")
.set("Content-Type", "text/plain")
.send("")
Expand All @@ -84,8 +75,7 @@ describe("Compiler", () => {
});

it("should only accept POST request", (done) => {
chai
.request(server)
request(server)
.get("/compile")
.send({
board: "sensebox-mcu",
Expand Down
22 changes: 7 additions & 15 deletions test/mcu.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
const chai = require("chai");
const chaiHttp = require("chai-http");
const server = require("../src/index");
const should = chai.should();
const fs = require("fs");

chai.use(chaiHttp);
import fs from "fs";
import server from "../src/index.js";
import request from "./setup.js";

describe("Compiler - MCU", () => {
let downloadId_mcu = "";

it("should compile an empty sketch for senseBox MCU", (done) => {
const sketch = fs.readFileSync("test/sketches/empty.ino", "utf8");

chai
.request(server)
request(server)
.post("/compile")
.send({ board: "sensebox-mcu", sketch })
.end((err, res) => {
Expand All @@ -27,8 +22,7 @@ describe("Compiler - MCU", () => {
it("should compile a hello world sketch for senseBox MCU", (done) => {
const sketch = fs.readFileSync("test/sketches/hello-world.ino", "utf8");

chai
.request(server)
request(server)
.post("/compile")
.send({ board: "sensebox-mcu", sketch })
.end((err, res) => {
Expand All @@ -42,8 +36,7 @@ describe("Compiler - MCU", () => {
it("should compile a senseBox:home sketch (from openSenseMap) for senseBox MCU", (done) => {
const sketch = fs.readFileSync("test/sketches/mcu/full-home.ino", "utf8");

chai
.request(server)
request(server)
.post("/compile")
.send({ board: "sensebox-mcu", sketch })
.end((err, res) => {
Expand All @@ -55,8 +48,7 @@ describe("Compiler - MCU", () => {
});

it("should download sketch for senseBox MCU", (done) => {
chai
.request(server)
request(server)
.get("/download")
.query({ board: "sensebox-mcu", id: downloadId_mcu })
.end((err, res) => {
Expand Down
22 changes: 7 additions & 15 deletions test/mcu_s2.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
const chai = require("chai");
const chaiHttp = require("chai-http");
const server = require("../src/index");
const fs = require("fs");
const should = chai.should();

chai.use(chaiHttp);
import fs from "fs";
import server from "../src/index.js";
import request from "./setup.js";

describe("Compiler - MCU S2 (ESP32S2)", () => {
let downloadId_esp32s2 = "";

it("should compile an empty sketch for senseBox MCU-S2 ESP32S2", (done) => {
const sketch = fs.readFileSync("test/sketches/empty.ino", "utf8");

chai
.request(server)
request(server)
.post("/compile")
.send({ board: "sensebox-esp32s2", sketch })
.end((err, res) => {
Expand All @@ -27,8 +22,7 @@ describe("Compiler - MCU S2 (ESP32S2)", () => {
it("should compile a hello world sketch for senseBox MCU-S2 ESP32S2", (done) => {
const sketch = fs.readFileSync("test/sketches/hello-world.ino", "utf8");

chai
.request(server)
request(server)
.post("/compile")
.send({ board: "sensebox-esp32s2", sketch })
.end((err, res) => {
Expand All @@ -44,8 +38,7 @@ describe("Compiler - MCU S2 (ESP32S2)", () => {
"test/sketches/mcu_s2/tof-distance-display.ino",
"utf8"
);
chai
.request(server)
request(server)
.post("/compile")
.send({ board: "sensebox-esp32s2", sketch })
.end((err, res) => {
Expand All @@ -57,8 +50,7 @@ describe("Compiler - MCU S2 (ESP32S2)", () => {
});

it("should download sketch for senseBox MCU-S2 ESP32S2", (done) => {
chai
.request(server)
request(server)
.get("/download")
.query({ board: "sensebox-esp32s2", id: downloadId_esp32s2 })
.end((err, res) => {
Expand Down
9 changes: 9 additions & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// test/setup.js
import { should, use } from "chai";
import chaiHttp from "chai-http";

const chai = use(chaiHttp);

should();

export default chai.request.execute;
19 changes: 6 additions & 13 deletions test/uno.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
const chai = require("chai");
const chaiHttp = require("chai-http");
const server = require("../src/index");
const should = chai.should();
const fs = require("fs");

chai.use(chaiHttp);
import fs from "fs";
import server from "../src/index.js";
import request from "./setup.js";

describe("Compiler - UNO", () => {
let downloadId_uno = "";

it("should compile an empty sketch for old senseBox", (done) => {
const sketch = fs.readFileSync("test/sketches/empty.ino", "utf8");

chai
.request(server)
request(server)
.post("/compile")
.send({ board: "sensebox", sketch })
.end((err, res) => {
Expand All @@ -33,8 +28,7 @@ describe("Compiler - UNO", () => {
it("should compile a hello world sketch for old senseBox", (done) => {
const sketch = fs.readFileSync("test/sketches/hello-world.ino", "utf8");

chai
.request(server)
request(server)
.post("/compile")
.send({ board: "sensebox", sketch })
.end((err, res) => {
Expand All @@ -52,8 +46,7 @@ describe("Compiler - UNO", () => {
});

it("should download sketch for old senseBox", (done) => {
chai
.request(server)
request(server)
.get("/download")
.query({ board: "sensebox", id: downloadId_uno })
.end((err, res) => {
Expand Down

0 comments on commit 222047c

Please # to comment.