Skip to content

Commit

Permalink
test(libs/constants): add test cases + new test:lib script
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed May 19, 2023
1 parent 9ebc27f commit 33ec69f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ jobs:
- name: Unit testing client
run: yarn test:client

- name: Unit testing libs
run: yarn test:libs

- name: Build and start server
id: server
env:
Expand Down
62 changes: 62 additions & 0 deletions libs/constants/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
createRegExpFromExtensions,
ANY_ATTACHMENT_REGEXP,
BINARY_ATTACHMENT_REGEXP,
} from "./index.js";

describe("createRegExpFromExt", () => {
const regexp = createRegExpFromExtensions("foo");

it("accepts the extension", () => {
expect(regexp.test("test.foo")).toEqual(true);
});

it("accepts uppercase", () => {
expect(regexp.test("test.FOO")).toEqual(true);
});

it("rejects intermediate extensions", () => {
expect(regexp.test("test.foo.bar")).toEqual(false);
});

it("rejects other extensions", () => {
expect(regexp.test("test.bar")).toEqual(false);
});

it("rejects extensions starting with it", () => {
expect(regexp.test("test.foob")).toEqual(false);
});

it("rejects extensions ending with it", () => {
expect(regexp.test("test.afoo")).toEqual(false);
});
});

describe("ANY_ATTACHMENT_REGEXP", () => {
const regexp = ANY_ATTACHMENT_REGEXP;
it("accepts audio files", () => {
expect(regexp.test("audio.mp3")).toEqual(true);
});

it("accepts video files", () => {
expect(regexp.test("video.mp4")).toEqual(true);
});

it("accepts font files", () => {
expect(regexp.test("diagram.svg")).toEqual(true);
});

["index.html", "index.json", "index.md", "contributors.txt"].forEach(
(filename) =>
it(`rejects ${filename}`, () => {
expect(regexp.test(filename)).toEqual(false);
})
);
});

describe("BINARY_ATTACHMENT_REGEXP", () => {
const regexp = BINARY_ATTACHMENT_REGEXP;
it("rejects svg files", () => {
expect(regexp.test("diagram.svg")).toEqual(false);
});
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@
"start:static-server": "ts-node server/static.ts",
"style-dictionary": "style-dictionary build -c sd-config.js",
"stylelint": "stylelint \"**/*.scss\"",
"test": "yarn prettier-check && yarn test:client && yarn test:kumascript && yarn test:content && yarn test:testing",
"test": "yarn prettier-check && yarn test:client && yarn test:kumascript && yarn test:libs && yarn test:content && yarn test:testing",
"test:client": "cd client && tsc --noEmit && cross-env NODE_ENV=test BABEL_ENV=test PUBLIC_URL='' node scripts/test.js --env=jsdom",
"test:content": "yarn jest --rootDir content",
"test:developing": "cross-env CONTENT_ROOT=mdn/content/files TESTING_DEVELOPING=true playwright test developing",
"test:headless": "playwright test headless",
"test:kumascript": "yarn jest --rootDir kumascript --env=node",
"test:libs": "yarn jest --rootDir libs --env=node",
"test:prepare": "yarn build:prepare && yarn build && yarn start:static-server",
"test:testing": "yarn jest --rootDir testing",
"tool": "ts-node tool/cli.ts",
Expand Down

0 comments on commit 33ec69f

Please sign in to comment.