Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
feat: setup initial testing libs, scripts and test utils.js (#19)
Browse files Browse the repository at this point in the history
* test: add ut for utils (#16)

* chore: add test:watch script

* refactor: separate dependencies imports (#16)

* chore: add node.js github workflow (#16)

* refactor: remove useless config

* fix: install deps with npm i instead npm ci

* fix: add c8 due to broken coverage
  • Loading branch information
PierreDemailly committed Jun 22, 2022
1 parent 387cf9e commit 2e9b8b3
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Node.js CI

on:
push:
branches:
- main
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm i
- name: Run tests
run: npm run test
nsci:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: NodeSecure/ci-action@v1
with:
warnings: warning
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"type": "module",
"exports": "./index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "tap --no-coverage",
"test:watch": "tap --watch",
"test:c8": "c8 tap --no-coverage",
"start": "npm run build && http-server ./dist",
"build": "node esbuild.config.js"
},
Expand Down Expand Up @@ -36,6 +38,7 @@
"@nodesecure/flags": "^2.3.0",
"@nodesecure/scanner": "^3.4.1",
"esbuild": "^0.14.42",
"http-server": "^14.1.0"
"http-server": "^14.1.0",
"tap": "^16.3.0"
}
}
65 changes: 65 additions & 0 deletions test/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Import Third-party Dependencies
import tap from "tap";

// Import Internal Dependencies
import { getFlagsEmojisInlined, getJSON, getNodeColor } from "../src/utils.js";
import * as CONSTANTS from "../src/constants.js";

const response = { message: "test should works" };
global.fetch = () => Promise.resolve({ json: () => response });
const json = await getJSON("random");

tap.equal(json, response, "getJSON should works");

const FLAGS = [
{
emoji: "🌍",
title: "hasExternalCapacity",
},
{
emoji: "🚧",
title: "hasWarnings",
},
{
emoji: "🐲",
title: "hasNativeCode",
},
];

const titles = FLAGS.map((flag) => flag.title);

tap.equal(
getFlagsEmojisInlined(titles, new Set()),
" 🌍 🚧 🐲",
"getFlagsEmojisInlined without flag to ignore"
);

tap.equal(
getFlagsEmojisInlined(titles, new Set(["hasWarnings"])),
" 🌍 🐲",
"getFlagsEmojisInlined with flag to ignore"
);

tap.equal(
getNodeColor(0),
CONSTANTS.COLORS["LIGHT"].SELECTED,
"id 0 is the root package (so by default he is highlighted as selected)."
);

tap.equal(
getNodeColor(1, true),
CONSTANTS.COLORS["LIGHT"].WARN,
"hasWarnings is true, so the node is highlighted as warning."
);

tap.equal(
getNodeColor(1, false),
CONSTANTS.COLORS["LIGHT"].DEFAULT,
"the node is highlighted as default."
);

tap.equal(
getNodeColor(1, false, "DARK"),
CONSTANTS.COLORS["DARK"].DEFAULT,
"the node is highlighted as default and the theme is DARK."
);

0 comments on commit 2e9b8b3

Please sign in to comment.