Skip to content

Commit

Permalink
Use mocha as an test runner.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledyba committed May 1, 2022
1 parent 3d68309 commit 6479c44
Show file tree
Hide file tree
Showing 11 changed files with 4,927 additions and 9,259 deletions.
9 changes: 9 additions & 0 deletions server/.mocharc.json
@@ -0,0 +1,9 @@
{
"extension": ["ts"],
"spec": "src/**/*.spec.ts",
"require": "ts-node/register",
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
]
}
14,085 changes: 4,876 additions & 9,209 deletions server/package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions server/package.json
Expand Up @@ -8,7 +8,7 @@
"build": "tsc",
"clean": "rm -Rf ./dist",
"up": "npm-check-updates -u && npm install && npm dedupe && npm audit fix",
"test": "jest"
"test": "mocha"
},
"exports": {
".": {
Expand All @@ -26,13 +26,12 @@
"license": "AGPL-3.0-or-later",
"devDependencies": {
"@types/generic-pool": "^3.1.10",
"@types/jest": "^27.4.1",
"@types/marked": "^4.0.3",
"@types/mocha": "^9.1.1",
"@types/node": "^17.0.23",
"esm": "^3.2.25",
"jest": "^27.5.1",
"assert": "^2.0.0",
"mocha": "^10.0.0",
"npm-check-updates": "^12.5.4",
"ts-jest": "^27.1.4",
"ts-node-dev": "^1.1.8"
},
"dependencies": {
Expand Down
12 changes: 0 additions & 12 deletions server/src/jest.config.js

This file was deleted.

8 changes: 4 additions & 4 deletions server/src/lib/Asset.test.ts → server/src/lib/Asset.spec.ts
@@ -1,12 +1,12 @@
// https://jestjs.io/docs/api
import {describe, expect, it } from '@jest/globals';
import fs from 'fs/promises';
import { describe, it } from 'mocha';
import assert from 'assert';
import fs from 'node:fs/promises';
import Asset from './Asset.js';

describe("Asset", () => {
it("Asset dir exists", async () => {
const asset = new Asset();
const stat = await fs.stat(asset.pathOf(''));
expect(stat).not.toBeNull;
assert.notEqual(stat, null);
});
});
24 changes: 12 additions & 12 deletions server/src/lib/fml.test.ts → server/src/lib/fml.spec.ts
@@ -1,27 +1,27 @@
// https://jestjs.io/docs/api
import {describe, expect, it } from '@jest/globals';
import { describe, it } from 'mocha';
import assert from 'assert';
import * as fml from './fml.js';

describe("FML", () => {
it("Parse empty", () => {
const buffer = new fml.Buffer(``);
const p = new fml.Parser(buffer);
expect(p.parse()).toEqual(new fml.Document([]));
assert.deepEqual(p.parse(), new fml.Document([]));
});
it("Simple text", () => {
const buffer = new fml.Buffer(`test`);
const p = new fml.Parser(buffer);
expect(p.parse()).toEqual(new fml.Document([fml.makeText(`test`)]));
assert.deepEqual(p.parse(), new fml.Document([fml.makeText(`test`)]));
});
it("Image block", () => {
const buffer = new fml.Buffer(`[image entity="test_id"]`);
const p = new fml.Parser(buffer);
expect(p.parse()).toEqual(new fml.Document([fml.makeImage("test_id")]));
assert.deepEqual(p.parse(), new fml.Document([fml.makeImage("test_id")]));
});
it("Image mixed", () => {
const buffer = new fml.Buffer(`aa[image entity="test_id"] aa`);
const p = new fml.Parser(buffer);
expect(p.parse()).toEqual(new fml.Document([
assert.deepEqual(p.parse(), new fml.Document([
fml.makeText("aa"),
fml.makeImage("test_id"),
fml.makeText("aa"),
Expand All @@ -30,28 +30,28 @@ describe("FML", () => {
it("Broken brancket", () => {
const buffer = new fml.Buffer(`aa[image entity="test`);
const p = new fml.Parser(buffer);
expect(p.parse()).toEqual(new fml.Document([
assert.deepEqual(p.parse(), (new fml.Document([
fml.makeText(`aa[image entity="test`),
]));
])));
});
it("Brancket with new line", () => {
const buffer = new fml.Buffer(`[image\r\nentity="test_id"]`);
const p = new fml.Parser(buffer);
expect(p.parse()).toEqual(new fml.Document([
assert.deepEqual(p.parse(), new fml.Document([
fml.makeImage("test_id"),
]));
});
it("One Paragraph", () => {
const buffer = new fml.Buffer(`\r\na\r\nb\nc\rd\r\n\r\n`);
const p = new fml.Parser(buffer);
expect(p.parse()).toEqual(new fml.Document([
assert.deepEqual(p.parse(), new fml.Document([
fml.makeText("abcd"),
]));
});
it("Paragraphs", () => {
const buffer = new fml.Buffer(`\r\na\r\n\r\nb\n\nc\r\rd\r\n\r\n`);
const p = new fml.Parser(buffer);
expect(p.parse()).toEqual(new fml.Document([
assert.deepEqual(p.parse(), new fml.Document([
fml.makeText("a"),
fml.makeText("b"),
fml.makeText("cd"),
Expand All @@ -60,6 +60,6 @@ describe("FML", () => {
it("Handle last", () => {
const buffer = new fml.Buffer(`[image entity="test_id"]\n `);
const p = new fml.Parser(buffer);
expect(p.parse()).toEqual(new fml.Document([fml.makeImage("test_id")]));
assert.deepEqual(p.parse(), new fml.Document([fml.makeImage("test_id")]));
});
});
File renamed without changes.
16 changes: 16 additions & 0 deletions server/src/lib/md5sum.spec.ts
@@ -0,0 +1,16 @@
import { describe, it } from 'mocha';
import assert from 'assert';

import * as path from 'path';
import { fileURLToPath } from 'url';

import md5sum from './md5sum.js';

const dirname = path.dirname(fileURLToPath(import.meta.url))

describe("MD5SUM", () => {
it("test empty", async () => {
const hash = await md5sum(path.join(dirname, 'md5sum.spec.empty.blob'));
assert.equal(hash, 'd41d8cd98f00b204e9800998ecf8427e');
});
});
11 changes: 0 additions & 11 deletions server/src/lib/md5sum.test.ts

This file was deleted.

@@ -1,13 +1,13 @@
// https://jestjs.io/docs/api
import {describe, expect, it } from '@jest/globals';
import { describe, it } from 'mocha';
import assert from 'assert';
import * as media from './Probe.js';
import Asset from '../Asset.js';

describe("Media", () => {
it("parse jpeg", async () => {
const filepath = new Asset().pathOf('static/omote/kaede.jpg');
const r = await media.probe(filepath);
expect(r.width).toEqual(1000);
expect(r.height).toEqual(1000);
assert.equal(r.width, 1000);
assert.equal(r.height, 1000);
});
});
4 changes: 2 additions & 2 deletions server/tsconfig.json
Expand Up @@ -4,9 +4,9 @@

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
"target": "ES2022", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
"module": "ES2022", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"lib": ["ESNext"], /* Specify library files to be included in the compilation. */
"lib": ["ES2021"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
Expand Down

0 comments on commit 6479c44

Please sign in to comment.