Installations
npm install cynic
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
18.15.0
NPM Version
9.5.0
Score
72
Supply Chain
96.8
Quality
74.4
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (93.62%)
JavaScript (2.58%)
Shell (2.28%)
HTML (1.52%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
chase-moskal
Download Statistics
Total Downloads
11,513
Last Day
1
Last Week
1
Last Month
232
Last Year
3,000
GitHub Statistics
5 Stars
98 Commits
2 Watching
1 Branches
1 Contributors
Package Meta Information
Latest Version
0.2.1
Package Id
cynic@0.2.1
Unpacked Size
113.66 kB
Size
30.90 kB
File Count
191
NPM Version
9.5.0
Node Version
18.15.0
Publised On
25 Mar 2023
Total Downloads
Cumulative downloads
Total Downloads
11,513
Last day
0%
1
Compared to previous day
Last week
-98%
1
Compared to previous week
Last month
19%
232
Compared to previous month
Last year
45.8%
3,000
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
🧐 cynic
async testing framework for es modules
- cynic is designed to be dirt-simple, because i'm sick of overcomplicated testing frameworks
- the test suites are just nested async functions
- the whole framework is just simple es modules that run anywhere: node, browser, puppeteer, deno
- no magic assumptions are made about or foisted onto the environment: the assertion library and everything else is just simply imported like from any other module
- examples here are shown in typescript, but of course you can use vanilla js
let's get cynical, and make a damn test suite!
-
install cynic into your project
1npm install --save-dev cynic
-
write a test suite,
example.test.ts
1import {Suite, assert, expect} from "cynic" 2 3export default <Suite>{ 4 "alpha system": { 5 "can sum two numbers (boolean return)": async() => { 6 const a = 1 7 const b = 2 8 // no assertion library required: 9 // simply returning false, or throwing, will fail a test 10 return (a + b) === 3 11 }, 12 "can sum three numbers (assert)": async() => { 13 const a = 1 14 const b = 2 15 const c = 3 16 // benefits of 'assert' 17 // - you get a stack trace 18 // - you can provide a custom message for each failure 19 assert((a + b + c) === 6, `sum is wrong`) 20 } 21 }, 22 "bravo system": { 23 "can multiply numbers (expect)": async() => { 24 const a = 2 25 const b = 3 26 // benefits of 'expect' 27 // - you get a stack trace 28 // - cynic tries to invent a message about the failure 29 expect(a * b).equals(6) 30 expect(a * b * a).equals(12) 31 } 32 } 33}
now run it!
-
you can run the suite file through the cynic cli
1# run your tests in node 2cynic node example.test.js 3 4# run your tests in browser 5cynic browser example.test.js 6 7# run your tests in puppeteer (headless browser) 8cynic puppeteer example.test.js 9 10# use node debugger 11node inspect node_modules/cynic/dist/cli.js node example.test.js
cynic executes the default export as a test suite
optional arguments for all runtimes:
--label="test suite"
— the report title
optional arguments for browser and puppeteer runtimes:
--open=false
— true to prompt open your default browser--port=8021
— run the server on a different port--origin="http://localhost:8021"
— connect to the server via an alternative url (mind the port number!)--cynic-path=node_modules/cynic
— use an alternative path to the cynic library's root--importmap-path=./dist/importmap.json
— provide an import map for your test suites
if puppeteer isn't running properly, see puppeteer's troubleshooting.md
-
or you can just execute your test suite, manually, anywhere
this should work anywhere you can import an es module
1import {test} from "cynic" 2import suite from "./example.test.js" 3 4;(async() => { 5 6 // run the test suite 7 const {report, ...stats} = await test("example suite", suite) 8 9 // emit the report text to console 10 console.log(report) 11 12 // handle results programmatically 13 if (stats.failed === 0) console.log("done") 14 else console.log("failed!") 15 16 // returns stats about the test run results 17 console.log(stats) 18 19})()
see which stats are available in the
Stats
interface in types.ts
so what do the console reports look like?
-
report: successful run
cynic example suite ▽ examples ▽ alpha system ✓ can sum two numbers (boolean return) ✓ can sum three numbers (assertion) ▽ bravo system ✓ can multiply numbers (expectation) 0 failed tests 0 thrown errors 3 passed tests 3 total tests 0.00 seconds
-
report: a test returns false
return false to indicate a failed testcynic example suite ▽ examples ▽ alpha system ═════ ✘ can sum two numbers (boolean return) ▽ bravo system ✘ can sum two numbers (boolean return) — failed 1 FAILED tests 0 thrown errors 2 passed tests 3 total tests 0.00 seconds
-
report: a test throws
a thrown string or error will be shown as the failure reasoncynic example suite ▽ examples ▽ alpha system ═════ ✘ can sum two numbers (boolean return) ――――――― arithmetic failed for interesting reasons ▽ bravo system ✘ can sum two numbers (boolean return) — arithmetic failed for interesting reasons 1 FAILED tests 1 thrown errors 2 passed tests 3 total tests 0.00 seconds
-
report: a test fails an assertion
assertions will display a stack trace, and optional custom messagecynic example suite ▽ examples ▽ alpha system ═════ ✘ can sum three numbers (assertion) ――――――― CynicBrokenAssertion: sum is wrong at assert (file:///work/cynic/dist/assert.js:7:15) at can sum three numbers (assertion) (file:///work/cynic/dist/internals/example.test.js:13:20) at execute (file:///work/cynic/dist/internals/execute.js:13:34) [...] ▽ bravo system ✘ can sum three numbers (assertion) — CynicBrokenAssertion: sum is wrong 1 FAILED tests 1 thrown errors 2 passed tests 3 total tests 0.00 seconds
-
report: a test fails an expectation
stack trace is provided, and a failure reason is generated automaticallycynic example suite ▽ examples ▽ alpha system ▽ bravo system ═════ ✘ can multiply numbers (expectation) ――――――― CynicBrokenExpectation: expect(7).equals(6): not equal, should be at composite (file:///work/cynic/dist/expect.js:46:19) at Object.equals (file:///work/cynic/dist/expect.js:25:125) at can multiply numbers (expectation) (file:///work/cynic/dist/internals/example.test.js:20:39) at execute (file:///work/cynic/dist/internals/execute.js:13:34) [...] ✘ can multiply numbers (expectation) — CynicBrokenExpectation: expect(7).equals(6): not equal, should be 1 FAILED tests 1 thrown errors 2 passed tests 3 total tests 0.00 seconds
hot tips for big brains
-
use object nesting to group and organize tests arbitrarily
1import {Suite} from "cynic" 2export default <Suite>{ 3 "nested tests": { 4 "more nested": { 5 "exceedingly nested": { 6 "it works": async() => true 7 } 8 } 9 } 10}
-
you can just throw strings as assertions
1import {Suite} from "cynic" 2export default <Suite>{ 3 "assertions and expectations": async() => { 4 const example = "abc" 5 6 // let's call it "the spartan assertion" 7 if (!example.includes("b")) 8 throw `expected example to include "b"` 9 10 return true 11 } 12}
-
or you can use the handy
assert
function to do that, you get stack traces1import {Suite, assert} from "cynic" 2export default <Suite>{ 3 "using 'assert'": async() => { 4 const example = "abc" 5 assert(example === "abc", `example must equal "abc"`) 6 assert(example.includes("b"), `example should include "b"`) 7 } 8}
-
or you can also use the experimental new
expect
api, you get auto-generated messages and stack traces1import {Suite, expect} from "cynic" 2export default <Suite>{ 3 "using 'expect'": async() => { 4 const example = "abc" 5 expect(example).defined() 6 expect(example).equals("abc") 7 } 8}
-
a suite or test can return another suite or test — easy setups!
1export default <Suite>(async() => { 2 3 // doing some async setup 4 const myFile = await loadFile("myfile.json") 5 6 // returning more tests 7 return { 8 "group of tests": { 9 "my file exists": async() => { 10 return !!myFile 11 } 12 } 13 } 14})
food for thought
- 🥃 chase moskal made this with open source love. please contribute!
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yaml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/chase-moskal/cynic/build.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yaml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/chase-moskal/cynic/build.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yaml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/chase-moskal/cynic/publish.yaml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yaml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/chase-moskal/cynic/publish.yaml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/publish.yaml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/chase-moskal/cynic/publish.yaml/master?enable=pin
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 2 out of 2 npmCommand dependencies pinned
Reason
7 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/build.yaml:1
- Warn: no topLevel permission defined: .github/workflows/publish.yaml:1
- Info: no jobLevel write permissions found
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
3.4
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to cynic
@yamiteru/cynic
Tiny and simple TS pub/sub library with great focus on performance.
@dsr-cynic-bates-paths-crude/dsr-package-public-cynic-bates-paths-crude
empty
@dsr-hooka-cynic-rajas-blees/dsr-package-public-hooka-cynic-rajas-blees
empty
@dsr-org-xylic-dryly-image-cynic/test-dsr-org-xylic-dryly-image-cynic
empty