This repository has been archived by the owner on Mar 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup initial testing libs, scripts and test utils.js (#19)
* 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
1 parent
387cf9e
commit 2e9b8b3
Showing
3 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
); |