migrate tests to node:test

This commit is contained in:
Girish Ramakrishnan
2026-02-18 22:21:54 +01:00
parent cf0ab16533
commit c176ac600b
94 changed files with 2680 additions and 3553 deletions

View File

@@ -1,15 +1,12 @@
import { describe, it, before, after } from 'node:test';
/* jslint node:true */
import constants from '../constants.js';
import expect from 'expect.js';
import assert from 'node:assert/strict';
import safe from 'safetydance';
import server from '../server.js';
import superagent from '@cloudron/superagent';
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
const SERVER_URL = 'http://localhost:' + constants.PORT;
@@ -23,12 +20,12 @@ describe('Server', function () {
it('is reachable', async function () {
const response = await superagent.get(SERVER_URL + '/api/v1/cloudron/status');
expect(response.status).to.equal(200);
assert.equal(response.status, 200);
});
it('should fail because already running', async function () {
const [error] = await safe(server.start());
expect(error).to.be.ok();
assert.ok(error);
});
});
@@ -38,21 +35,21 @@ describe('Server', function () {
it('random bad superagents', async function () {
const response = await superagent.get(SERVER_URL + '/random').ok(() => true);
expect(response.status).to.equal(404);
assert.equal(response.status, 404);
});
it('version', async function () {
const response = await superagent.get(SERVER_URL + '/api/v1/cloudron/status');
expect(response.status).to.equal(200);
expect(response.body.version).to.contain('-test');
assert.equal(response.status, 200);
assert.ok(response.body.version.includes('-test'));
});
it('status route is GET', async function () {
const response = await superagent.post(SERVER_URL + '/api/v1/cloudron/status').ok(() => true);
expect(response.status).to.equal(404);
assert.equal(response.status, 404);
const response2 = await superagent.get(SERVER_URL + '/api/v1/cloudron/status');
expect(response2.status).to.equal(200);
assert.equal(response2.status, 200);
});
});
@@ -62,12 +59,12 @@ describe('Server', function () {
it('config fails due missing token', async function () {
const response = await superagent.get(SERVER_URL + '/api/v1/dashboard/config').ok(() => true);
expect(response.status).to.equal(401);
assert.equal(response.status, 401);
});
it('config fails due wrong token', async function () {
const response = await superagent.get(SERVER_URL + '/api/v1/dashboard/config').query({ access_token: 'somewrongtoken' }).ok(() => true);
expect(response.status).to.equal(401);
assert.equal(response.status, 401);
});
});
@@ -76,7 +73,7 @@ describe('Server', function () {
it('is not reachable anymore', async function () {
const [error] = await safe(superagent.get(SERVER_URL + '/api/v1/cloudron/status').ok(() => true));
expect(error).to.not.be(null);
assert.notEqual(error, null);
});
});
});