Compare commits

..

No commits in common. "master" and "7.2.1" have entirely different histories.

30 changed files with 4089 additions and 943 deletions

View File

@ -9,6 +9,24 @@
"parserOptions": { "parserOptions": {
"ecmaVersion": 2022 "ecmaVersion": 2022
}, },
"overrides": [
{
"files": [
"**/*.test.js"
],
"env": {
"jest": true
},
"plugins": ["jest"],
"rules": {
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error"
}
}
],
"env": { "env": {
"node": true, "node": true,
"es6": true "es6": true
@ -62,8 +80,14 @@
"linebreak-style": [0], "linebreak-style": [0],
"node/no-missing-require": [0], "node/no-missing-require": [0],
"no-console": [0], "no-console": [0],
"node/no-unsupported-features/es-builtins": 0, "node/no-unsupported-features/es-builtins": [
"node/no-unsupported-features/node-builtins": 0, "error",
{ "version": ">=18.12.1" }
],
"node/no-unsupported-features/node-builtins": [
"error",
{ "version": ">=18.12.1" }
],
"func-names": [ "func-names": [
"error", "error",
"never", "never",

2
.gitattributes vendored
View File

@ -1 +1 @@
test-addon/binding.gyp linguist-vendored test/binding.gyp linguist-vendored

View File

@ -1,47 +0,0 @@
name: Cpplint
defaults:
run:
shell: bash
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
eslint:
name: Cpplint
runs-on: ubuntu-20.04
steps:
- name: Fetch Repository
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18.16.0
cache: 'npm'
- name: Install Modules
run: npm ci
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install Cpplint
run: pip install cpplint
- name: Run Cpplint
run: |
node -e "require('.').cpcpplint()"
cpplint --recursive ./test-addon
cpplint --recursive ./include

View File

@ -1,36 +0,0 @@
name: ESLint
defaults:
run:
shell: bash
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
eslint:
name: ESLint
runs-on: ubuntu-20.04
steps:
- name: Fetch Repository
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18.16.0
cache: 'npm'
- name: Install Modules
run: npm ci
- name: Run ESLint
run: npm run eslint

View File

@ -21,7 +21,7 @@ jobs:
- name: Install Node.js - name: Install Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: 18.16.0 node-version: 18.12.1
cache: 'npm' cache: 'npm'
- name: Get Package Version - name: Get Package Version

View File

@ -1,4 +1,4 @@
name: Test name: Validate
defaults: defaults:
run: run:
shell: bash shell: bash
@ -12,6 +12,29 @@ on:
- master - master
jobs: jobs:
eslint:
name: ESLint
runs-on: ubuntu-20.04
steps:
- name: Fetch Repository
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18.12.1
cache: 'npm'
- name: Install Modules
run: npm ci
- name: Run ESLint
run: npm run eslint
unit-tests: unit-tests:
name: Unit Tests name: Unit Tests
strategy: strategy:
@ -30,7 +53,7 @@ jobs:
- name: Install Node.js - name: Install Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: 18.16.0 node-version: 18.12.1
cache: 'npm' cache: 'npm'
- name: Install Modules - name: Install Modules

1
.gitignore vendored
View File

@ -6,4 +6,5 @@
.DS_Store .DS_Store
node_modules/ node_modules/
test-addon/build/ test-addon/build/
doc/jest/
*.log *.log

View File

@ -5,7 +5,7 @@
"includePath": [ "includePath": [
"${workspaceFolder}/**", "${workspaceFolder}/**",
"${LocalAppData}/node-gyp/Cache/16.17.0/include/node", "${LocalAppData}/node-gyp/Cache/16.17.0/include/node",
"${LocalAppData}/node-gyp/Cache/18.16.0/include/node" "${LocalAppData}/node-gyp/Cache/18.12.1/include/node"
], ],
"windowsSdkVersion": "10.0.19041.0", "windowsSdkVersion": "10.0.19041.0",
"cStandard": "c17", "cStandard": "c17",

View File

@ -1,18 +1,17 @@
set noparent set noparent
linelength=110 linelength=110
filter=-build/header_guard
filter=-build/include
filter=-build/include_order
filter=-build/include_what_you_use
filter=-build/namespaces
filter=-legal/copyright filter=-legal/copyright
filter=-readability/todo filter=-build/include_order
filter=-runtime/indentation_namespace filter=-build/include
filter=-build/header_guard
filter=-build/namespaces
filter=-build/include_what_you_use
filter=-whitespace/blank_line filter=-whitespace/blank_line
filter=-whitespace/braces
filter=-whitespace/comments filter=-whitespace/comments
filter=-whitespace/tab
filter=-whitespace/end_of_line filter=-whitespace/end_of_line
filter=-whitespace/indent filter=-whitespace/indent
filter=-whitespace/operators filter=-whitespace/operators
filter=-whitespace/parens filter=-whitespace/parens
filter=-whitespace/tab filter=-readability/todo
filter=-runtime/indentation_namespace

View File

@ -3,12 +3,10 @@
This is a part of [Node3D](https://github.com/node-3d) project. This is a part of [Node3D](https://github.com/node-3d) project.
[![NPM](https://badge.fury.io/js/addon-tools-raub.svg)](https://badge.fury.io/js/addon-tools-raub) [![NPM](https://badge.fury.io/js/addon-tools-raub.svg)](https://badge.fury.io/js/addon-tools-raub)
[![ESLint](https://github.com/node-3d/addon-tools-raub/actions/workflows/eslint.yml/badge.svg)](https://github.com/node-3d/addon-tools-raub/actions/workflows/eslint.yml) [![CodeFactor](https://www.codefactor.io/repository/github/node-3d/addon-tools-raub/badge)](https://www.codefactor.io/repository/github/node-3d/addon-tools-raub)
[![Test](https://github.com/node-3d/addon-tools-raub/actions/workflows/test.yml/badge.svg)](https://github.com/node-3d/addon-tools-raub/actions/workflows/test.yml)
[![Cpplint](https://github.com/node-3d/addon-tools-raub/actions/workflows/cpplint.yml/badge.svg)](https://github.com/node-3d/addon-tools-raub/actions/workflows/cpplint.yml)
``` ```
npm i -s addon-tools-raub npm i addon-tools-raub
``` ```
@ -67,9 +65,9 @@ See the [TypeScript definitions](/index.d.ts) with comments.
the **napi.h** include path won't be a part of the returned string. the **napi.h** include path won't be a part of the returned string.
### Example of `cpbin` in **package.json :: scripts**: ### Example of `cpbin` usage in **package.json :: scripts**:
``` ```
"build": "cd src && node-gyp rebuild -j max --silent && node -e \"require('addon-tools-raub').cpbin('segfault')\" && cd ..", "build-all": "cd src && node-gyp rebuild -j max --silent && node -e \"require('addon-tools-raub').cpbin('segfault')\" && cd ..",
"build-only": "cd src && node-gyp build -j max --silent && node -e \"require('addon-tools-raub').cpbin('segfault')\" && cd ..", "build-only": "cd src && node-gyp build -j max --silent && node -e \"require('addon-tools-raub').cpbin('segfault')\" && cd ..",
``` ```

20
conf/jest.json Normal file
View File

@ -0,0 +1,20 @@
{
"rootDir": "../",
"moduleFileExtensions": [
"js",
"node"
],
"testMatch": [
"<rootDir>/**/*.test.js"
],
"coverageDirectory": "doc/jest",
"coverageReporters": [
"lcov"
],
"collectCoverageFrom": [
"**/*.js",
"!**/*.test.js",
"!index.js",
"!utils.js"
]
}

View File

@ -1,8 +1,5 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const tools = require('.'); const tools = require('.');
@ -12,30 +9,30 @@ describe('AT / include', () => {
stringMethods.forEach((name) => { stringMethods.forEach((name) => {
describe(`#${name}()`, () => { describe(`#${name}()`, () => {
it('is a function', () => { it('is a function', () => {
assert.strictEqual(typeof tools[name], 'function'); expect(typeof tools[name]).toBe('function');
}); });
it('returns an object', () => { it('returns an object', () => {
assert.strictEqual(typeof tools[name](), 'string'); expect(typeof tools[name]()).toBe('string');
}); });
}); });
}); });
describe('#getPaths()', () => { describe('#getPaths()', () => {
it('is a function', () => { it('is a function', () => {
assert.strictEqual(typeof tools.getPaths, 'function'); expect(typeof tools.getPaths).toBe('function');
}); });
it('returns an object', () => { it('returns an object', () => {
assert.strictEqual(typeof tools.getPaths(__dirname), 'object'); expect(typeof tools.getPaths(__dirname)).toBe('object');
}); });
it('has "include" string', () => { it('has "include" string', () => {
assert.strictEqual(typeof tools.getPaths(__dirname).include, 'string'); expect(typeof tools.getPaths(__dirname).include).toBe('string');
}); });
it('has "bin" string', () => { it('has "bin" string', () => {
assert.strictEqual(typeof tools.getPaths(__dirname).include, 'string'); expect(typeof tools.getPaths(__dirname).include).toBe('string');
}); });
}); });
}); });

400
index.d.ts vendored
View File

@ -1,26 +1,22 @@
declare module "addon-tools-raub" { import type { Stats } from 'node:fs';
type Stats = import('node:fs').Stats; import type { Writable } from 'node:stream';
type Writable = import('node:stream').Writable;
type Readable = import('node:stream').Readable;
type WritableOptions = import('node:stream').WritableOptions;
declare module "addon-tools-raub" {
/** /**
* Get the internal paths for an addon * Get the internal paths for an addon
* * Returns a set of platform dependent paths depending on the input dir
* Returns a set of platform dependent paths depending on the input dir */
*/
export const getPaths: (dir: string) => Readonly<{ export const getPaths: (dir: string) => Readonly<{
/** /**
* Path to binaries * Path to binaries
* * Platform binary directory absolute path for this `dir`
* Platform binary directory absolute path for this `dir` */
*/
bin: string; bin: string;
/** /**
* Path to include * Path to include
* * Include directory for this `dir`
* Include directory for this `dir` */
*/
include: string; include: string;
}>; }>;
@ -28,334 +24,214 @@ declare module "addon-tools-raub" {
type TPlatformDir = `bin-${TPlatformName}`; type TPlatformDir = `bin-${TPlatformName}`;
/** /**
* Get the platform-specific binary directory name * Get the platform-specific binary directory name
*/ */
export const getBin: () => TPlatformDir; export const getBin: () => TPlatformDir;
/** /**
* Get the platform identifier * Get the platform identifier
*/ */
export const getPlatform: () => TPlatformName; export const getPlatform: () => TPlatformName;
/** /**
* Get the include directories for **binding.gyp** * Get the include directories for **binding.gyp**
* * Both 'addon-tools-raub' and 'node-addon-api' include paths.
* Both 'addon-tools-raub' and 'node-addon-api' include paths. * In binding.gyp: `'<!@(node -p "require(\'addon-tools-raub\').getInclude()")'`
* In binding.gyp: `'<!@(node -p "require(\'addon-tools-raub\').getInclude()")'` */
*/
export const getInclude: () => string; export const getInclude: () => string;
/** /**
* Install binaries * Install binaries
* * Downloads and unpacks the platform specific binary for the calling package.
* Downloads and unpacks the platform specific binary for the calling package. * To use it, create a new script for your package, which may as well be named
* To use it, create a new script for your package, which may as well be named * **install.js**, with the following content:
* **install.js**, with the following content: *
* * ```
* ``` * 'use strict';
* 'use strict'; * const { install } = require('addon-tools-raub');
* const { install } = require('addon-tools-raub'); * const prefix = 'https://github.com/USER/ADDON-NAME/releases/download';
* const prefix = 'https://github.com/USER/ADDON-NAME/releases/download'; * const tag = '1.0.0';
* const tag = '1.0.0'; * install(`${prefix}/${tag}`);
* install(`${prefix}/${tag}`); * ```
* ``` *
* * * `prefix` - the constant base part of the download url.
* * `prefix` - the constant base part of the download url. * * `tag` - the version-dependent part of the url.
* * `tag` - the version-dependent part of the url. *
* * ```
* ``` * "scripts": {
* "scripts": { * "postinstall": "node install"
* "postinstall": "node install" * },
* }, * ```
* ``` */
*/
export const install: (folder: string) => Promise<boolean>; export const install: (folder: string) => Promise<boolean>;
/** /**
* Copy binary * Copy binary
* * Copies the addon binary from `src/build/Release` to the platform-specific folder.
* Copies the addon binary from `src/build/Release` to the platform-specific folder. *
* * ```
* ``` * "scripts": {
* "scripts": { * * "build": "node-gyp rebuild && node -e \"require('addon-tools-raub').cpbin('ADDON')\""
* * "build": "node-gyp rebuild && node -e \"require('addon-tools-raub').cpbin('ADDON')\"" * },
* }, * ```
* ``` *
* * Here ADDON should be replaced with the name of your addon, without `.node` extension.
* Here ADDON should be replaced with the name of your addon, without `.node` extension. */
*/
export const cpbin: (name: string) => Promise<void>; export const cpbin: (name: string) => Promise<void>;
/** /**
* Packs binaries into GZIP * Packs binaries into GZIP
* * Example of `actionPack` usage in **Github Actions**:
* Example of `actionPack` usage in **Github Actions**: *
* * ```
* ``` * - name: Pack Files
* - name: Pack Files * id: pack-files
* id: pack-files * run: node -e "require('addon-tools-raub').actionPack()" >> $GITHUB_OUTPUT
* run: node -e "require('addon-tools-raub').actionPack()" >> $GITHUB_OUTPUT * - name: Store Binaries
* - name: Store Binaries * uses: softprops/action-gh-release@v1
* uses: softprops/action-gh-release@v1 * with:
* with: * files: ${{ steps.pack-files.outputs.pack }}
* files: ${{ steps.pack-files.outputs.pack }} * ```
* ``` */
*/
export const actionPack: () => Promise<void>; export const actionPack: () => Promise<void>;
/** /**
* Download to memory * Download to memory
* * Accepts an **URL**, and returns an in-memory file Buffer,
* Accepts an **URL**, and returns an in-memory file Buffer, * when the file is loaded. Use for small files, as the whole
* when the file is loaded. Use for small files, as the whole * file will be loaded into memory at once.
* file will be loaded into memory at once. *
* * ```
* ``` * download(srcUrl).then(data => useData(data), err => emit('error', err));
* download(srcUrl).then(data => useData(data), err => emit('error', err)); * ```
* ``` * or
* or * ```
* ``` * const data = await download(srcUrl);
* const data = await download(srcUrl); * useData(data);
* useData(data); * ```
* ``` */
*/
export const download: (url: string) => Promise<Buffer>; export const download: (url: string) => Promise<Buffer>;
/** /**
* (async) Read a file * (async) Read a file
* * Reads a whole file to string, NOT A Buffer
* Reads a whole file to string, NOT A Buffer */
*/
type ComposeFnParam = (source: any) => void;
/** /**
* WritableBuffer * WritableBuffer
* * A [Writable](https://nodejs.org/api/stream.html#stream_writable_streams)
* A [Writable](https://nodejs.org/api/stream.html#stream_writable_streams) * stream buffer, that is stored in-memory and can be fully
* stream buffer, that is stored in-memory and can be fully * obtained when writing was finished. It is equivalent to stream-writing
* obtained when writing was finished. It is equivalent to stream-writing * a temporary file and then reading it into a `Buffer`.
* a temporary file and then reading it into a `Buffer`. */
*/ export class WritableBuffer extends Writable {
export class WritableBuffer implements Writable {
constructor(); constructor();
/** /**
* Get the downloaded data * Get the downloaded data
* Use `stream.get()` to obtain the data when writing was finished * Use `stream.get()` to obtain the data when writing was finished
*/ */
get(): Buffer; get(): Buffer;
// ----------- implements Writable
readonly writable: boolean;
readonly writableEnded: boolean;
readonly writableFinished: boolean;
readonly writableHighWaterMark: number;
readonly writableLength: number;
readonly writableObjectMode: boolean;
readonly writableCorked: number;
destroyed: boolean;
readonly closed: boolean;
readonly errored: Error | null;
readonly writableNeedDrain: boolean;
constructor(opts?: WritableOptions);
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
_writev?(
chunks: Array<{
chunk: any;
encoding: BufferEncoding;
}>,
callback: (error?: Error | null) => void,
): void;
_construct?(callback: (error?: Error | null) => void): void;
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
_final(callback: (error?: Error | null) => void): void;
write(chunk: any, callback?: (error: Error | null | undefined) => void): boolean;
write(chunk: any, encoding: BufferEncoding, callback?: (error: Error | null | undefined) => void): boolean;
setDefaultEncoding(encoding: BufferEncoding): this;
end(cb?: () => void): this;
end(chunk: any, cb?: () => void): this;
end(chunk: any, encoding: BufferEncoding, cb?: () => void): this;
cork(): void;
uncork(): void;
destroy(error?: Error): this;
addListener(event: "close", listener: () => void): this;
addListener(event: "drain", listener: () => void): this;
addListener(event: "error", listener: (err: Error) => void): this;
addListener(event: "finish", listener: () => void): this;
addListener(event: "pipe", listener: (src: Readable) => void): this;
addListener(event: "unpipe", listener: (src: Readable) => void): this;
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
emit(event: "close"): boolean;
emit(event: "drain"): boolean;
emit(event: "error", err: Error): boolean;
emit(event: "finish"): boolean;
emit(event: "pipe", src: Readable): boolean;
emit(event: "unpipe", src: Readable): boolean;
emit(event: string | symbol, ...args: any[]): boolean;
on(event: "close", listener: () => void): this;
on(event: "drain", listener: () => void): this;
on(event: "error", listener: (err: Error) => void): this;
on(event: "finish", listener: () => void): this;
on(event: "pipe", listener: (src: Readable) => void): this;
on(event: "unpipe", listener: (src: Readable) => void): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
once(event: "close", listener: () => void): this;
once(event: "drain", listener: () => void): this;
once(event: "error", listener: (err: Error) => void): this;
once(event: "finish", listener: () => void): this;
once(event: "pipe", listener: (src: Readable) => void): this;
once(event: "unpipe", listener: (src: Readable) => void): this;
once(event: string | symbol, listener: (...args: any[]) => void): this;
prependListener(event: "close", listener: () => void): this;
prependListener(event: "drain", listener: () => void): this;
prependListener(event: "error", listener: (err: Error) => void): this;
prependListener(event: "finish", listener: () => void): this;
prependListener(event: "pipe", listener: (src: Readable) => void): this;
prependListener(event: "unpipe", listener: (src: Readable) => void): this;
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
prependOnceListener(event: "close", listener: () => void): this;
prependOnceListener(event: "drain", listener: () => void): this;
prependOnceListener(event: "error", listener: (err: Error) => void): this;
prependOnceListener(event: "finish", listener: () => void): this;
prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
removeListener(event: "close", listener: () => void): this;
removeListener(event: "drain", listener: () => void): this;
removeListener(event: "error", listener: (err: Error) => void): this;
removeListener(event: "finish", listener: () => void): this;
removeListener(event: "pipe", listener: (src: Readable) => void): this;
removeListener(event: "unpipe", listener: (src: Readable) => void): this;
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
pipe<T extends NodeJS.WritableStream>(
destination: T,
options?: {
end?: boolean | undefined;
},
): T;
compose<T extends NodeJS.ReadableStream>(
stream: T | ComposeFnParam | Iterable<T> | AsyncIterable<T>,
options?: { signal: AbortSignal },
): T;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
removeAllListeners(event?: string | symbol): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
listeners(eventName: string | symbol): Function[];
rawListeners(eventName: string | symbol): Function[];
emit(eventName: string | symbol, ...args: any[]): boolean;
listenerCount(eventName: string | symbol, listener?: Function): number;
eventNames(): Array<string | symbol>;
} }
export const read: (name: string) => Promise<string>; export const read: (name: string) => Promise<string>;
/** /**
* (async) Write a file * (async) Write a file
*/ */
export const write: (name: string, text: string) => Promise<void>; export const write: (name: string, text: string) => Promise<void>;
/** /**
* (async) Copy a file * (async) Copy a file
*/ */
export const copy: (src: string, dest: string) => Promise<void>; export const copy: (src: string, dest: string) => Promise<void>;
/** /**
* (async) Check if a file/folder exists * (async) Check if a file/folder exists
*/ */
export const exists: (name: string) => Promise<boolean>; export const exists: (name: string) => Promise<boolean>;
/** /**
* (async) Create an empty folder * (async) Create an empty folder
*/ */
export const mkdir: (name: string) => Promise<void>; export const mkdir: (name: string) => Promise<void>;
/** /**
* (async) Get status on a file * (async) Get status on a file
*/ */
export const stat: (name: string) => Promise<Stats>; export const stat: (name: string) => Promise<Stats>;
/** /**
* (async) Check if the path is a folder * (async) Check if the path is a folder
*/ */
export const isDir: (name: string) => Promise<boolean>; export const isDir: (name: string) => Promise<boolean>;
/** /**
* (async) Check if the path is a file * (async) Check if the path is a file
*/ */
export const isFile: (name: string) => Promise<boolean>; export const isFile: (name: string) => Promise<boolean>;
/** /**
* Cut the path one folder up * Cut the path one folder up
*/ */
export const dirUp: (dir: string) => string; export const dirUp: (dir: string) => string;
/** /**
* (async) Create a directory * (async) Create a directory
* * Like `mkdir -p`, makes sure a directory exists
* Like `mkdir -p`, makes sure a directory exists */
*/
export const ensuredir: (dir: string) => Promise<void>; export const ensuredir: (dir: string) => Promise<void>;
/** /**
* (async) Copy a file * (async) Copy a file
* * Copy a file, `dest` folder is created if needed
* Copy a file, `dest` folder is created if needed */
*/
export const copysafe: (src: string, dest: string) => Promise<void>; export const copysafe: (src: string, dest: string) => Promise<void>;
/** /**
* (async) Read a directory * (async) Read a directory
* * Get file/folder names of the 1st level
* Get file/folder names of the 1st level */
*/
export const readdir: (src: string, dest: string) => Promise<ReadonlyArray<string>>; export const readdir: (src: string, dest: string) => Promise<ReadonlyArray<string>>;
/** /**
* (async) List subdirectories * (async) List subdirectories
* * Get folder paths (concatenated with input) of the 1st level
* Get folder paths (concatenated with input) of the 1st level */
*/
export const subdirs: (name: string) => Promise<ReadonlyArray<string>>; export const subdirs: (name: string) => Promise<ReadonlyArray<string>>;
/** /**
* (async) List nested files * (async) List nested files
* * Get file paths (concatenated with input) of the 1st level
* Get file paths (concatenated with input) of the 1st level */
*/
export const subfiles: (name: string) => Promise<ReadonlyArray<string>>; export const subfiles: (name: string) => Promise<ReadonlyArray<string>>;
/** /**
* (async) Get all nested files recursively * (async) Get all nested files recursively
* * Folder paths are omitted by default.
* Folder paths are omitted by default. * Order is: shallow-to-deep, each subdirectory lists dirs-then-files.
* Order is: shallow-to-deep, each subdirectory lists dirs-then-files. */
*/
export const traverse: (name: string, showDirs?: boolean) => Promise<ReadonlyArray<string>>; export const traverse: (name: string, showDirs?: boolean) => Promise<ReadonlyArray<string>>;
/** /**
* (async) Copy a directory * (async) Copy a directory
* * Copy a folder with all the contained files
* Copy a folder with all the contained files */
*/
export const copyall: (src: string, dest: string) => Promise<void>; export const copyall: (src: string, dest: string) => Promise<void>;
/** /**
* (async) Remove a directory * (async) Remove a directory
* * Like `rm -rf`, removes everything recursively
* Like `rm -rf`, removes everything recursively */
*/
export const rmdir: (name: string) => Promise<void>; export const rmdir: (name: string) => Promise<void>;
/** /**
* (async) Remove a file * (async) Remove a file
* * Must be a file, not a folder. Just `fs.unlink`.
* Must be a file, not a folder. Just `fs.unlink`. */
*/
export const rm: (name: string) => Promise<void>; export const rm: (name: string) => Promise<void>;
} }

3582
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{ {
"author": "Luis Blanco <luisblanco1337@gmail.com>", "author": "Luis Blanco <luisblanco1337@gmail.com>",
"name": "addon-tools-raub", "name": "addon-tools-raub",
"version": "7.4.0", "version": "7.2.1",
"description": "Helpers for Node.js addons and dependency packages", "description": "Helpers for Node.js addons and dependency packages",
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "index.js",
@ -34,8 +34,9 @@
}, },
"scripts": { "scripts": {
"eslint": "eslint .", "eslint": "eslint .",
"test": "node --test --watch .", "test": "jest --coverage=false --watch --config=conf/jest.json",
"test-ci": "node --test", "test-ci": "jest --ci --runInBand --coverage=false --forceExit --detectOpenHandles --config=conf/jest.json",
"test-coverage": "rm -rf doc/jest && jest --coverage --silent --config=conf/jest.json",
"build-test": "cd test-addon && node-gyp rebuild -j max --silent && cd .." "build-test": "cd test-addon && node-gyp rebuild -j max --silent && cd .."
}, },
"repository": { "repository": {
@ -43,18 +44,17 @@
"url": "https://github.com/node-3d/addon-tools-raub.git" "url": "https://github.com/node-3d/addon-tools-raub.git"
}, },
"peerDependencies": { "peerDependencies": {
"node-addon-api": "^7.0.0" "node-addon-api": "^6.1.0"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {
"node-addon-api": { "node-addon-api": { "optional": true }
"optional": true
}
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^20.8.3", "eslint-plugin-jest": "^27.2.1",
"eslint": "^8.51.0",
"eslint-plugin-node": "^11.1.0", "eslint-plugin-node": "^11.1.0",
"node-addon-api": "^7.0.0", "eslint": "^8.40.0",
"typescript": "^5.2.2" "jest": "^29.5.0",
"node-addon-api": "^6.1.0",
"typescript": "^5.0.4"
} }
} }

View File

@ -1,45 +1,42 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const test = require('./build/Release/test.node'); const test = require('./build/Release/test.node');
const arrayArgLetMsg = { message: 'Argument 0 must be of type `Array` or be `null`/`undefined`' }; const arrayArgMsg = 'Argument 0 must be of type `Array`';
describe('AT / HPP / LET_ARRAY_ARG', () => { describe('AT / addon-tools.hpp / LET_ARRAY_ARG', () => {
it('exports letArrayStrArg', () => { it('exports letArrayStrArg', () => {
assert.strictEqual(typeof test.letArrayStrArg, 'function'); expect(typeof test.letArrayStrArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.letArrayStrArg('1'), arrayArgLetMsg); expect(() => test.letArrayStrArg('1')).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.letArrayStrArg(1), arrayArgLetMsg); expect(() => test.letArrayStrArg(1)).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.letArrayStrArg(true), arrayArgLetMsg); expect(() => test.letArrayStrArg(true)).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a pointer', () => { it('throws if arg was passed a pointer', () => {
assert.throws(() => test.letArrayStrArg(test.retExt()), arrayArgLetMsg); expect(() => test.letArrayStrArg(test.retExt())).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.letArrayStrArg({}), arrayArgLetMsg); expect(() => test.letArrayStrArg({})).toThrow(arrayArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.ok(Array.isArray(test.letArrayStrArg())); expect(Array.isArray(test.letArrayStrArg())).toBe(true);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.ok(Array.isArray(test.letArrayStrArg(undefined))); expect(Array.isArray(test.letArrayStrArg(undefined))).toBe(true);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.ok(Array.isArray(test.letArrayStrArg(null))); expect(Array.isArray(test.letArrayStrArg(null))).toBe(true);
}); });
it('accepts an array', () => { it('accepts an array', () => {
assert.ok(Array.isArray(test.letArrayStrArg([]))); expect(Array.isArray(test.letArrayStrArg([]))).toBe(true);
}); });
it('returns same array', () => { it('returns same array', () => {
assert.deepStrictEqual(test.letArrayStrArg(['a', 'b']),['a', 'b']); expect(test.letArrayStrArg(['a', 'b'])).toEqual(['a', 'b']);
}); });
}); });

View File

@ -1,109 +1,105 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const test = require('./build/Release/test.node'); const test = require('./build/Release/test.node');
const arrayArgMsg = { message: 'Argument 0 must be of type `Array`' }; const arrayArgMsg = 'Argument 0 must be of type `Array`';
const arrayArgLetMsg = { message: 'Argument 0 must be of type `Array` or be `null`/`undefined`' };
describe('AT / HPP / REQ_ARRAY_ARG', () => { describe('AT / addon-tools.hpp / REQ_ARRAY_ARG', () => {
it('exports reqArrayArg', () => { it('exports reqArrayArg', () => {
assert.strictEqual(typeof test.reqArrayArg, 'function'); expect(typeof test.reqArrayArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqArrayArg(), arrayArgMsg); expect(() => test.reqArrayArg()).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqArrayArg(undefined), arrayArgMsg); expect(() => test.reqArrayArg(undefined)).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqArrayArg(null), arrayArgMsg); expect(() => test.reqArrayArg(null)).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqArrayArg('1'), arrayArgMsg); expect(() => test.reqArrayArg('1')).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.reqArrayArg(1), arrayArgMsg); expect(() => test.reqArrayArg(1)).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqArrayArg(true), arrayArgMsg); expect(() => test.reqArrayArg(true)).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a pointer', () => { it('throws if arg was passed a pointer', () => {
assert.throws(() => test.reqArrayArg(test.retExt()), arrayArgMsg); expect(() => test.reqArrayArg(test.retExt())).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqArrayArg({}), arrayArgMsg); expect(() => test.reqArrayArg({})).toThrow(arrayArgMsg);
}); });
it('accepts an array', () => { it('accepts an array', () => {
assert.ok(Array.isArray(test.reqArrayArg([]))); expect(Array.isArray(test.reqArrayArg([]))).toBe(true);
}); });
}); });
describe('addon-tools.hpp: LET_ARRAY_ARG', () => { describe('addon-tools.hpp: LET_ARRAY_ARG', () => {
it('exports letArrayArg', () => { it('exports letArrayArg', () => {
assert.strictEqual(typeof test.letArrayArg, 'function'); expect(typeof test.letArrayArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.letArrayArg('1'), arrayArgLetMsg); expect(() => test.letArrayArg('1')).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.letArrayArg(1), arrayArgLetMsg); expect(() => test.letArrayArg(1)).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.letArrayArg(true), arrayArgLetMsg); expect(() => test.letArrayArg(true)).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a pointer', () => { it('throws if arg was passed a pointer', () => {
assert.throws(() => test.letArrayArg(test.retExt()), arrayArgLetMsg); expect(() => test.letArrayArg(test.retExt())).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.letArrayArg({}), arrayArgLetMsg); expect(() => test.letArrayArg({})).toThrow(arrayArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.ok(Array.isArray(test.letArrayArg())); expect(Array.isArray(test.letArrayArg())).toBe(true);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.ok(Array.isArray(test.letArrayArg(undefined))); expect(Array.isArray(test.letArrayArg(undefined))).toBe(true);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.ok(Array.isArray(test.letArrayArg(null))); expect(Array.isArray(test.letArrayArg(null))).toBe(true);
}); });
it('accepts an array', () => { it('accepts an array', () => {
assert.ok(Array.isArray(test.letArrayArg([]))); expect(Array.isArray(test.letArrayArg([]))).toBe(true);
}); });
}); });
describe('addon-tools.hpp: USE_ARRAY_ARG', () => { describe('addon-tools.hpp: USE_ARRAY_ARG', () => {
it('exports useArrayArg', () => { it('exports useArrayArg', () => {
assert.strictEqual(typeof test.useArrayArg, 'function'); expect(typeof test.useArrayArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.useArrayArg('1'), arrayArgLetMsg); expect(() => test.useArrayArg('1')).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.useArrayArg(1), arrayArgLetMsg); expect(() => test.useArrayArg(1)).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.useArrayArg(true), arrayArgLetMsg); expect(() => test.useArrayArg(true)).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed a pointer', () => { it('throws if arg was passed a pointer', () => {
assert.throws(() => test.useArrayArg(test.retExt()), arrayArgLetMsg); expect(() => test.useArrayArg(test.retExt())).toThrow(arrayArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.useArrayArg({}), arrayArgLetMsg); expect(() => test.useArrayArg({})).toThrow(arrayArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.ok(Array.isArray(test.useArrayArg())); expect(Array.isArray(test.useArrayArg())).toBe(true);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.ok(Array.isArray(test.useArrayArg(undefined))); expect(Array.isArray(test.useArrayArg(undefined))).toBe(true);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.ok(Array.isArray(test.useArrayArg(null))); expect(Array.isArray(test.useArrayArg(null))).toBe(true);
}); });
it('accepts an array', () => { it('accepts an array', () => {
assert.ok(Array.isArray(test.useArrayArg([]))); expect(Array.isArray(test.useArrayArg([]))).toBe(true);
}); });
}); });

View File

@ -1,100 +1,96 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const test = require('./build/Release/test.node'); const test = require('./build/Release/test.node');
const boolArgMsg = { message: 'Argument 0 must be of type `Bool`' }; const boolArgMsg = 'Argument 0 must be of type `Bool`';
const boolArgLetMsg = { message: 'Argument 0 must be of type `Bool` or be `null`/`undefined`' };
describe('AT / HPP / REQ_BOOL_ARG', () => { describe('AT / addon-tools.hpp / REQ_BOOL_ARG', () => {
it('exports reqBoolArg', () => { it('exports reqBoolArg', () => {
assert.strictEqual(typeof test.reqBoolArg, 'function'); expect(typeof test.reqBoolArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqBoolArg(), boolArgMsg); expect(() => test.reqBoolArg()).toThrow(boolArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqBoolArg(undefined), boolArgMsg); expect(() => test.reqBoolArg(undefined)).toThrow(boolArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqBoolArg(null), boolArgMsg); expect(() => test.reqBoolArg(null)).toThrow(boolArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqBoolArg('1'), boolArgMsg); expect(() => test.reqBoolArg('1')).toThrow(boolArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.reqBoolArg(1), boolArgMsg); expect(() => test.reqBoolArg(1)).toThrow(boolArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqBoolArg({}), boolArgMsg); expect(() => test.reqBoolArg({})).toThrow(boolArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.reqBoolArg([]), boolArgMsg); expect(() => test.reqBoolArg([])).toThrow(boolArgMsg);
}); });
it('accepts a boolean', () => { it('accepts a boolean', () => {
assert.ok(test.reqBoolArg(true)); expect(test.reqBoolArg(true)).toEqual(true);
}); });
}); });
describe('addon-tools.hpp: LET_BOOL_ARG', () => { describe('addon-tools.hpp: LET_BOOL_ARG', () => {
it('exports letBoolArg', () => { it('exports letBoolArg', () => {
assert.strictEqual(typeof test.letBoolArg, 'function'); expect(typeof test.letBoolArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.letBoolArg('1'), boolArgLetMsg); expect(() => test.letBoolArg('1')).toThrow(boolArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.letBoolArg(1), boolArgLetMsg); expect(() => test.letBoolArg(1)).toThrow(boolArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.letBoolArg({}), boolArgLetMsg); expect(() => test.letBoolArg({})).toThrow(boolArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.letBoolArg([]), boolArgLetMsg); expect(() => test.letBoolArg([])).toThrow(boolArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.letBoolArg(), false); expect(test.letBoolArg()).toEqual(false);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.letBoolArg(undefined), false); expect(test.letBoolArg(undefined)).toEqual(false);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.letBoolArg(null), false); expect(test.letBoolArg(null)).toEqual(false);
}); });
it('accepts a boolean', () => { it('accepts a boolean', () => {
assert.ok(test.letBoolArg(true)); expect(test.letBoolArg(true)).toEqual(true);
}); });
}); });
describe('addon-tools.hpp: USE_BOOL_ARG', () => { describe('addon-tools.hpp: USE_BOOL_ARG', () => {
it('exports useBoolArg', () => { it('exports useBoolArg', () => {
assert.strictEqual(typeof test.useBoolArg, 'function'); expect(typeof test.useBoolArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.useBoolArg('1'), boolArgLetMsg); expect(() => test.useBoolArg('1')).toThrow(boolArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.useBoolArg(1), boolArgLetMsg); expect(() => test.useBoolArg(1)).toThrow(boolArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.useBoolArg({}), boolArgLetMsg); expect(() => test.useBoolArg({})).toThrow(boolArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.useBoolArg([]), boolArgLetMsg); expect(() => test.useBoolArg([])).toThrow(boolArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.ok(test.useBoolArg()); expect(test.useBoolArg()).toEqual(true);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.ok(test.useBoolArg(undefined)); expect(test.useBoolArg(undefined)).toEqual(true);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.ok(test.useBoolArg(null)); expect(test.useBoolArg(null)).toEqual(true);
}); });
it('accepts a boolean', () => { it('accepts a boolean', () => {
assert.ok(test.useBoolArg(true)); expect(test.useBoolArg(true)).toEqual(true);
}); });
}); });

View File

@ -1,100 +1,96 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const test = require('./build/Release/test.node'); const test = require('./build/Release/test.node');
const numArgMsg = { message: 'Argument 0 must be of type `Number`' }; const numArgMsg = 'Argument 0 must be of type `Number`';
const numArgLetMsg = { message: 'Argument 0 must be of type `Number` or be `null`/`undefined`' };
describe('AT / HPP / REQ_DOUBLE_ARG', () => { describe('AT / addon-tools.hpp / REQ_DOUBLE_ARG', () => {
it('exports reqDoubleArg', () => { it('exports reqDoubleArg', () => {
assert.strictEqual(typeof test.reqDoubleArg, 'function'); expect(typeof test.reqDoubleArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqDoubleArg(), numArgMsg); expect(() => test.reqDoubleArg()).toThrow(numArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqDoubleArg(undefined), numArgMsg); expect(() => test.reqDoubleArg(undefined)).toThrow(numArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqDoubleArg(null), numArgMsg); expect(() => test.reqDoubleArg(null)).toThrow(numArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqDoubleArg('1'), numArgMsg); expect(() => test.reqDoubleArg('1')).toThrow(numArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqDoubleArg(true), numArgMsg); expect(() => test.reqDoubleArg(true)).toThrow(numArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqDoubleArg({}), numArgMsg); expect(() => test.reqDoubleArg({})).toThrow(numArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.reqDoubleArg([]), numArgMsg); expect(() => test.reqDoubleArg([])).toThrow(numArgMsg);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.reqDoubleArg(55), 55); expect(test.reqDoubleArg(55)).toEqual(55);
}); });
}); });
describe('addon-tools.hpp: LET_DOUBLE_ARG', () => { describe('addon-tools.hpp: LET_DOUBLE_ARG', () => {
it('exports letDoubleArg', () => { it('exports letDoubleArg', () => {
assert.strictEqual(typeof test.letDoubleArg, 'function'); expect(typeof test.letDoubleArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.letDoubleArg('1'), numArgLetMsg); expect(() => test.letDoubleArg('1')).toThrow(numArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.letDoubleArg(true), numArgLetMsg); expect(() => test.letDoubleArg(true)).toThrow(numArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.letDoubleArg({}), numArgLetMsg); expect(() => test.letDoubleArg({})).toThrow(numArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.letDoubleArg([]), numArgLetMsg); expect(() => test.letDoubleArg([])).toThrow(numArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.letDoubleArg(), 0); expect(test.letDoubleArg()).toEqual(0);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.letDoubleArg(undefined), 0); expect(test.letDoubleArg(undefined)).toEqual(0);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.letDoubleArg(null), 0); expect(test.letDoubleArg(null)).toEqual(0);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.letDoubleArg(55), 55); expect(test.letDoubleArg(55)).toEqual(55);
}); });
}); });
describe('addon-tools.hpp: USE_DOUBLE_ARG', () => { describe('addon-tools.hpp: USE_DOUBLE_ARG', () => {
it('exports useDoubleArg', () => { it('exports useDoubleArg', () => {
assert.strictEqual(typeof test.useDoubleArg, 'function'); expect(typeof test.useDoubleArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.useDoubleArg('1'), numArgLetMsg); expect(() => test.useDoubleArg('1')).toThrow(numArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.useDoubleArg(true), numArgLetMsg); expect(() => test.useDoubleArg(true)).toThrow(numArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.useDoubleArg({}), numArgLetMsg); expect(() => test.useDoubleArg({})).toThrow(numArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.useDoubleArg([]), numArgLetMsg); expect(() => test.useDoubleArg([])).toThrow(numArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.useDoubleArg(), 10); expect(test.useDoubleArg()).toEqual(10);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.useDoubleArg(undefined), 10); expect(test.useDoubleArg(undefined)).toEqual(10);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.useDoubleArg(null), 10); expect(test.useDoubleArg(null)).toEqual(10);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.useDoubleArg(55), 55); expect(test.useDoubleArg(55)).toEqual(55);
}); });
}); });

View File

@ -1,109 +1,105 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const test = require('./build/Release/test.node'); const test = require('./build/Release/test.node');
const extArgMsg = { message: 'Argument 0 must be of type `Pointer`' }; const extArgMsg = 'Argument 0 must be of type `Pointer`';
const extArgLetMsg = { message: 'Argument 0 must be of type `Pointer` or be `null`/`undefined`' };
describe('AT / HPP / REQ_EXT_ARG', () => { describe('AT / addon-tools.hpp / REQ_EXT_ARG', () => {
it('exports reqExtArg', () => { it('exports reqExtArg', () => {
assert.strictEqual(typeof test.reqExtArg, 'function'); expect(typeof test.reqExtArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqExtArg(), extArgMsg); expect(() => test.reqExtArg()).toThrow(extArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqExtArg(undefined), extArgMsg); expect(() => test.reqExtArg(undefined)).toThrow(extArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqExtArg(null), extArgMsg); expect(() => test.reqExtArg(null)).toThrow(extArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqExtArg('1'), extArgMsg); expect(() => test.reqExtArg('1')).toThrow(extArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.reqExtArg(1), extArgMsg); expect(() => test.reqExtArg(1)).toThrow(extArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqExtArg(true), extArgMsg); expect(() => test.reqExtArg(true)).toThrow(extArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqExtArg({}), extArgMsg); expect(() => test.reqExtArg({})).toThrow(extArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.reqExtArg([]), extArgMsg); expect(() => test.reqExtArg([])).toThrow(extArgMsg);
}); });
it('accepts a pointer', () => { it('accepts a pointer', () => {
assert.strictEqual(typeof test.reqExtArg(test.retExt()), 'object'); expect(typeof test.reqExtArg(test.retExt())).toBe('object');
}); });
}); });
describe('addon-tools.hpp: LET_EXT_ARG', () => { describe('addon-tools.hpp: LET_EXT_ARG', () => {
it('exports letExtArg', () => { it('exports letExtArg', () => {
assert.strictEqual(typeof test.letExtArg, 'function'); expect(typeof test.letExtArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.letExtArg('1'), extArgLetMsg); expect(() => test.letExtArg('1')).toThrow(extArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.letExtArg(1), extArgLetMsg); expect(() => test.letExtArg(1)).toThrow(extArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.letExtArg(true), extArgLetMsg); expect(() => test.letExtArg(true)).toThrow(extArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.letExtArg({}), extArgLetMsg); expect(() => test.letExtArg({})).toThrow(extArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.letExtArg([]), extArgLetMsg); expect(() => test.letExtArg([])).toThrow(extArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(typeof test.letExtArg(), 'object'); expect(typeof test.letExtArg()).toBe('object');
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(typeof test.letExtArg(undefined), 'object'); expect(typeof test.letExtArg(undefined)).toBe('object');
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(typeof test.letExtArg(null), 'object'); expect(typeof test.letExtArg(null)).toBe('object');
}); });
it('accepts a pointer', () => { it('accepts a pointer', () => {
assert.strictEqual(typeof test.reqExtArg(test.retExt()), 'object'); expect(typeof test.reqExtArg(test.retExt())).toBe('object');
}); });
}); });
describe('addon-tools.hpp: USE_EXT_ARG', () => { describe('addon-tools.hpp: USE_EXT_ARG', () => {
it('exports useExtArg', () => { it('exports useExtArg', () => {
assert.strictEqual(typeof test.useExtArg, 'function'); expect(typeof test.useExtArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.useExtArg('1'), extArgLetMsg); expect(() => test.useExtArg('1')).toThrow(extArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.useExtArg(1), extArgLetMsg); expect(() => test.useExtArg(1)).toThrow(extArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.useExtArg(true), extArgLetMsg); expect(() => test.useExtArg(true)).toThrow(extArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.useExtArg({}), extArgLetMsg); expect(() => test.useExtArg({})).toThrow(extArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.useExtArg([]), extArgLetMsg); expect(() => test.useExtArg([])).toThrow(extArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(typeof test.useExtArg(), 'object'); expect(typeof test.useExtArg()).toBe('object');
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(typeof test.useExtArg(undefined), 'object'); expect(typeof test.useExtArg(undefined)).toBe('object');
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(typeof test.useExtArg(null), 'object'); expect(typeof test.useExtArg(null)).toBe('object');
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(typeof test.useExtArg(test.retExt()), 'object'); expect(typeof test.useExtArg(test.retExt())).toBe('object');
}); });
}); });

View File

@ -1,100 +1,96 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const test = require('./build/Release/test.node'); const test = require('./build/Release/test.node');
const numArgMsg = { message: 'Argument 0 must be of type `Number`' }; const numArgMsg = 'Argument 0 must be of type `Number`';
const numArgLetMsg = { message: 'Argument 0 must be of type `Number` or be `null`/`undefined`' };
describe('AT / HPP / REQ_FLOAT_ARG', () => { describe('AT / addon-tools.hpp / REQ_FLOAT_ARG', () => {
it('exports reqFloatArg', () => { it('exports reqFloatArg', () => {
assert.strictEqual(typeof test.reqFloatArg, 'function'); expect(typeof test.reqFloatArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqFloatArg(), numArgMsg); expect(() => test.reqFloatArg()).toThrow(numArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqFloatArg(undefined), numArgMsg); expect(() => test.reqFloatArg(undefined)).toThrow(numArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqFloatArg(null), numArgMsg); expect(() => test.reqFloatArg(null)).toThrow(numArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqFloatArg('1'), numArgMsg); expect(() => test.reqFloatArg('1')).toThrow(numArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqFloatArg(true), numArgMsg); expect(() => test.reqFloatArg(true)).toThrow(numArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqFloatArg({}), numArgMsg); expect(() => test.reqFloatArg({})).toThrow(numArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.reqFloatArg([]), numArgMsg); expect(() => test.reqFloatArg([])).toThrow(numArgMsg);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.reqFloatArg(55), 55); expect(test.reqFloatArg(55)).toEqual(55);
}); });
}); });
describe('addon-tools.hpp: LET_FLOAT_ARG', () => { describe('addon-tools.hpp: LET_FLOAT_ARG', () => {
it('exports letFloatArg', () => { it('exports letFloatArg', () => {
assert.strictEqual(typeof test.letFloatArg, 'function'); expect(typeof test.letFloatArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.letFloatArg('1'), numArgLetMsg); expect(() => test.letFloatArg('1')).toThrow(numArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.letFloatArg(true), numArgLetMsg); expect(() => test.letFloatArg(true)).toThrow(numArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.letFloatArg({}), numArgLetMsg); expect(() => test.letFloatArg({})).toThrow(numArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.letFloatArg([]), numArgLetMsg); expect(() => test.letFloatArg([])).toThrow(numArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.letFloatArg(), 0); expect(test.letFloatArg()).toEqual(0);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.letFloatArg(undefined), 0); expect(test.letFloatArg(undefined)).toEqual(0);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.letFloatArg(null), 0); expect(test.letFloatArg(null)).toEqual(0);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.letFloatArg(55), 55); expect(test.letFloatArg(55)).toEqual(55);
}); });
}); });
describe('addon-tools.hpp: USE_FLOAT_ARG', () => { describe('addon-tools.hpp: USE_FLOAT_ARG', () => {
it('exports useFloatArg', () => { it('exports useFloatArg', () => {
assert.strictEqual(typeof test.useFloatArg, 'function'); expect(typeof test.useFloatArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.useFloatArg('1'), numArgLetMsg); expect(() => test.useFloatArg('1')).toThrow(numArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.useFloatArg(true), numArgLetMsg); expect(() => test.useFloatArg(true)).toThrow(numArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.useFloatArg({}), numArgLetMsg); expect(() => test.useFloatArg({})).toThrow(numArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.useFloatArg([]), numArgLetMsg); expect(() => test.useFloatArg([])).toThrow(numArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.useFloatArg(), 10); expect(test.useFloatArg()).toEqual(10);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.useFloatArg(undefined), 10); expect(test.useFloatArg(undefined)).toEqual(10);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.useFloatArg(null), 10); expect(test.useFloatArg(null)).toEqual(10);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.useFloatArg(55), 55); expect(test.useFloatArg(55)).toEqual(55);
}); });
}); });

View File

@ -1,100 +1,96 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const test = require('./build/Release/test.node'); const test = require('./build/Release/test.node');
const intArgMsg = { message: 'Argument 0 must be of type `Int32`' }; const intArgMsg = 'Argument 0 must be of type `Int32`';
const intArgLetMsg = { message: 'Argument 0 must be of type `Int32` or be `null`/`undefined`' };
describe('AT / HPP / REQ_INT_ARG, REQ_INT32_ARG', () => { describe('AT / addon-tools.hpp / REQ_INT_ARG, REQ_INT32_ARG', () => {
it('exports reqIntArg', () => { it('exports reqIntArg', () => {
assert.strictEqual(typeof test.reqIntArg, 'function'); expect(typeof test.reqIntArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqIntArg(), intArgMsg); expect(() => test.reqIntArg()).toThrow(intArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqIntArg(undefined), intArgMsg); expect(() => test.reqIntArg(undefined)).toThrow(intArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqIntArg(null), intArgMsg); expect(() => test.reqIntArg(null)).toThrow(intArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqIntArg('1'), intArgMsg); expect(() => test.reqIntArg('1')).toThrow(intArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqIntArg(true), intArgMsg); expect(() => test.reqIntArg(true)).toThrow(intArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqIntArg({}), intArgMsg); expect(() => test.reqIntArg({})).toThrow(intArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.reqIntArg([]), intArgMsg); expect(() => test.reqIntArg([])).toThrow(intArgMsg);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.reqIntArg(55), 55); expect(test.reqIntArg(55)).toEqual(55);
}); });
}); });
describe('addon-tools.hpp: LET_INT_ARG / LET_INT32_ARG', () => { describe('addon-tools.hpp: LET_INT_ARG / LET_INT32_ARG', () => {
it('exports letIntArg', () => { it('exports letIntArg', () => {
assert.strictEqual(typeof test.letIntArg, 'function'); expect(typeof test.letIntArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.letIntArg('1'), intArgLetMsg); expect(() => test.letIntArg('1')).toThrow(intArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.letIntArg(true), intArgLetMsg); expect(() => test.letIntArg(true)).toThrow(intArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.letIntArg({}), intArgLetMsg); expect(() => test.letIntArg({})).toThrow(intArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.letIntArg([]), intArgLetMsg); expect(() => test.letIntArg([])).toThrow(intArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.letIntArg(), 0); expect(test.letIntArg()).toEqual(0);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.letIntArg(undefined), 0); expect(test.letIntArg(undefined)).toEqual(0);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.letIntArg(null), 0); expect(test.letIntArg(null)).toEqual(0);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.letIntArg(55), 55); expect(test.letIntArg(55)).toEqual(55);
}); });
}); });
describe('addon-tools.hpp: USE_INT_ARG / USE_INT32_ARG', () => { describe('addon-tools.hpp: USE_INT_ARG / USE_INT32_ARG', () => {
it('exports useIntArg', () => { it('exports useIntArg', () => {
assert.strictEqual(typeof test.useIntArg, 'function'); expect(typeof test.useIntArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.useIntArg('1'), intArgLetMsg); expect(() => test.useIntArg('1')).toThrow(intArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.useIntArg(true), intArgLetMsg); expect(() => test.useIntArg(true)).toThrow(intArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.useIntArg({}), intArgLetMsg); expect(() => test.useIntArg({})).toThrow(intArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.useIntArg([]), intArgLetMsg); expect(() => test.useIntArg([])).toThrow(intArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.useIntArg(), 10); expect(test.useIntArg()).toEqual(10);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.useIntArg(undefined), 10); expect(test.useIntArg(undefined)).toEqual(10);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.useIntArg(null), 10); expect(test.useIntArg(null)).toEqual(10);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.useIntArg(55), 55); expect(test.useIntArg(55)).toEqual(55);
}); });
}); });

View File

@ -1,109 +1,105 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const test = require('./build/Release/test.node'); const test = require('./build/Release/test.node');
const objArgMsg = { message: 'Argument 0 must be of type `Object`' }; const objArgMsg = 'Argument 0 must be of type `Object`';
const objArgLetMsg = { message: 'Argument 0 must be of type `Object` or be `null`/`undefined`' };
describe('AT / HPP / REQ_OBJ_ARG', () => { describe('AT / addon-tools.hpp / REQ_OBJ_ARG', () => {
it('exports reqObjArg', () => { it('exports reqObjArg', () => {
assert.strictEqual(typeof test.reqObjArg, 'function'); expect(typeof test.reqObjArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqObjArg(), objArgMsg); expect(() => test.reqObjArg()).toThrow(objArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqObjArg(undefined), objArgMsg); expect(() => test.reqObjArg(undefined)).toThrow(objArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqObjArg(null), objArgMsg); expect(() => test.reqObjArg(null)).toThrow(objArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqObjArg('1'), objArgMsg); expect(() => test.reqObjArg('1')).toThrow(objArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.reqObjArg(1), objArgMsg); expect(() => test.reqObjArg(1)).toThrow(objArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqObjArg(true), objArgMsg); expect(() => test.reqObjArg(true)).toThrow(objArgMsg);
}); });
it('throws if arg was passed a pointer', () => { it('throws if arg was passed a pointer', () => {
assert.throws(() => test.reqObjArg(test.retExt()), objArgMsg); expect(() => test.reqObjArg(test.retExt())).toThrow(objArgMsg);
}); });
it('accepts an object', () => { it('accepts an object', () => {
assert.strictEqual(typeof test.reqObjArg({}), 'object'); expect(typeof test.reqObjArg({})).toBe('object');
}); });
it('accepts an array', () => { it('accepts an array', () => {
assert.ok(Array.isArray(test.reqObjArg([]))); expect(Array.isArray(test.reqObjArg([]))).toBe(true);
}); });
}); });
describe('addon-tools.hpp: LET_OBJ_ARG', () => { describe('addon-tools.hpp: LET_OBJ_ARG', () => {
it('exports letObjArg', () => { it('exports letObjArg', () => {
assert.strictEqual(typeof test.letObjArg, 'function'); expect(typeof test.letObjArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.letObjArg('1'), objArgLetMsg); expect(() => test.letObjArg('1')).toThrow(objArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.letObjArg(1), objArgLetMsg); expect(() => test.letObjArg(1)).toThrow(objArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.letObjArg(true), objArgLetMsg); expect(() => test.letObjArg(true)).toThrow(objArgMsg);
}); });
it('throws if arg was passed a pointer', () => { it('throws if arg was passed a pointer', () => {
assert.throws(() => test.letObjArg(test.retExt()), objArgLetMsg); expect(() => test.letObjArg(test.retExt())).toThrow(objArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(typeof test.letObjArg(), 'object'); expect(typeof test.letObjArg()).toBe('object');
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(typeof test.letObjArg(undefined), 'object'); expect(typeof test.letObjArg(undefined)).toBe('object');
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(typeof test.letObjArg(null), 'object'); expect(typeof test.letObjArg(null)).toBe('object');
}); });
it('accepts an object', () => { it('accepts an object', () => {
assert.strictEqual(typeof test.letObjArg({}), 'object'); expect(typeof test.letObjArg({})).toBe('object');
}); });
it('accepts an array', () => { it('accepts an array', () => {
assert.ok(Array.isArray(test.letObjArg([]))); expect(Array.isArray(test.letObjArg([]))).toBe(true);
}); });
}); });
describe('addon-tools.hpp: USE_OBJ_ARG', () => { describe('addon-tools.hpp: USE_OBJ_ARG', () => {
it('exports useObjArg', () => { it('exports useObjArg', () => {
assert.strictEqual(typeof test.useObjArg, 'function'); expect(typeof test.useObjArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.useObjArg('1'), objArgLetMsg); expect(() => test.useObjArg('1')).toThrow(objArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.useObjArg(1), objArgLetMsg); expect(() => test.useObjArg(1)).toThrow(objArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.useObjArg(true), objArgLetMsg); expect(() => test.useObjArg(true)).toThrow(objArgMsg);
}); });
it('throws if arg was passed a pointer', () => { it('throws if arg was passed a pointer', () => {
assert.throws(() => test.useObjArg(test.retExt()), objArgLetMsg); expect(() => test.useObjArg(test.retExt())).toThrow(objArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(typeof test.useObjArg(), 'object'); expect(typeof test.useObjArg()).toBe('object');
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(typeof test.useObjArg(undefined), 'object'); expect(typeof test.useObjArg(undefined)).toBe('object');
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(typeof test.useObjArg(null), 'object'); expect(typeof test.useObjArg(null)).toBe('object');
}); });
it('accepts an object', () => { it('accepts an object', () => {
assert.strictEqual(typeof test.useObjArg({}), 'object'); expect(typeof test.useObjArg({})).toBe('object');
}); });
it('accepts an array', () => { it('accepts an array', () => {
assert.ok(Array.isArray(test.useObjArg([]))); expect(Array.isArray(test.useObjArg([]))).toBe(true);
}); });
}); });

View File

@ -1,100 +1,96 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const test = require('./build/Release/test.node'); const test = require('./build/Release/test.node');
const numArgMsg = { message: 'Argument 0 must be of type `Number`' }; const numArgMsg = 'Argument 0 must be of type `Number`';
const numArgLetMsg = { message: 'Argument 0 must be of type `Number` or be `null`/`undefined`' };
describe('AT / HPP / REQ_OFFS_ARG', () => { describe('AT / addon-tools.hpp / REQ_OFFS_ARG', () => {
it('exports reqOffsArg', () => { it('exports reqOffsArg', () => {
assert.strictEqual(typeof test.reqOffsArg, 'function'); expect(typeof test.reqOffsArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqOffsArg(), numArgMsg); expect(() => test.reqOffsArg()).toThrow(numArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqOffsArg(undefined), numArgMsg); expect(() => test.reqOffsArg(undefined)).toThrow(numArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqOffsArg(null), numArgMsg); expect(() => test.reqOffsArg(null)).toThrow(numArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqOffsArg('1'), numArgMsg); expect(() => test.reqOffsArg('1')).toThrow(numArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqOffsArg(true), numArgMsg); expect(() => test.reqOffsArg(true)).toThrow(numArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqOffsArg({}), numArgMsg); expect(() => test.reqOffsArg({})).toThrow(numArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.reqOffsArg([]), numArgMsg); expect(() => test.reqOffsArg([])).toThrow(numArgMsg);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.reqOffsArg(55), 55); expect(test.reqOffsArg(55)).toEqual(55);
}); });
}); });
describe('addon-tools.hpp: LET_OFFS_ARG', () => { describe('addon-tools.hpp: LET_OFFS_ARG', () => {
it('exports letOffsArg', () => { it('exports letOffsArg', () => {
assert.strictEqual(typeof test.letOffsArg, 'function'); expect(typeof test.letOffsArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.letOffsArg('1'), numArgLetMsg); expect(() => test.letOffsArg('1')).toThrow(numArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.letOffsArg(true), numArgLetMsg); expect(() => test.letOffsArg(true)).toThrow(numArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.letOffsArg({}), numArgLetMsg); expect(() => test.letOffsArg({})).toThrow(numArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.letOffsArg([]), numArgLetMsg); expect(() => test.letOffsArg([])).toThrow(numArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.letOffsArg(), 0); expect(test.letOffsArg()).toEqual(0);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.letOffsArg(undefined), 0); expect(test.letOffsArg(undefined)).toEqual(0);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.letOffsArg(null), 0); expect(test.letOffsArg(null)).toEqual(0);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.letOffsArg(55), 55); expect(test.letOffsArg(55)).toEqual(55);
}); });
}); });
describe('addon-tools.hpp: USE_OFFS_ARG', () => { describe('addon-tools.hpp: USE_OFFS_ARG', () => {
it('exports useOffsArg', () => { it('exports useOffsArg', () => {
assert.strictEqual(typeof test.useOffsArg, 'function'); expect(typeof test.useOffsArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.useOffsArg('1'), numArgLetMsg); expect(() => test.useOffsArg('1')).toThrow(numArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.useOffsArg(true), numArgLetMsg); expect(() => test.useOffsArg(true)).toThrow(numArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.useOffsArg({}), numArgLetMsg); expect(() => test.useOffsArg({})).toThrow(numArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.useOffsArg([]), numArgLetMsg); expect(() => test.useOffsArg([])).toThrow(numArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.useOffsArg(), 10); expect(test.useOffsArg()).toEqual(10);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.useOffsArg(undefined), 10); expect(test.useOffsArg(undefined)).toEqual(10);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.useOffsArg(null), 10); expect(test.useOffsArg(null)).toEqual(10);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.useOffsArg(55), 55); expect(test.useOffsArg(55)).toEqual(55);
}); });
}); });

View File

@ -1,100 +1,96 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const test = require('./build/Release/test.node'); const test = require('./build/Release/test.node');
const strArgMsg = { message: 'Argument 0 must be of type `String`' }; const strArgMsg = 'Argument 0 must be of type `String`';
const strArgLetMsg = { message: 'Argument 0 must be of type `String` or be `null`/`undefined`' };
describe('AT / HPP / REQ_STR_ARG', () => { describe('AT / addon-tools.hpp / REQ_STR_ARG', () => {
it('exports reqStrArg', () => { it('exports reqStrArg', () => {
assert.strictEqual(typeof test.reqStrArg, 'function'); expect(typeof test.reqStrArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqStrArg(), strArgMsg); expect(() => test.reqStrArg()).toThrow(strArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqStrArg(undefined), strArgMsg); expect(() => test.reqStrArg(undefined)).toThrow(strArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqStrArg(null), strArgMsg); expect(() => test.reqStrArg(null)).toThrow(strArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.reqStrArg(1), strArgMsg); expect(() => test.reqStrArg(1)).toThrow(strArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqStrArg(true), strArgMsg); expect(() => test.reqStrArg(true)).toThrow(strArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqStrArg({}), strArgMsg); expect(() => test.reqStrArg({})).toThrow(strArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.reqStrArg([]), strArgMsg); expect(() => test.reqStrArg([])).toThrow(strArgMsg);
}); });
it('accepts a string', () => { it('accepts a string', () => {
assert.strictEqual(test.reqStrArg('1abc'), '1abc'); expect(test.reqStrArg('1abc')).toEqual('1abc');
}); });
}); });
describe('addon-tools.hpp: LET_STR_ARG', () => { describe('addon-tools.hpp: LET_STR_ARG', () => {
it('exports letStrArg', () => { it('exports letStrArg', () => {
assert.strictEqual(typeof test.letStrArg, 'function'); expect(typeof test.letStrArg).toBe('function');
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.letStrArg(1), strArgLetMsg); expect(() => test.letStrArg(1)).toThrow(strArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.letStrArg(true), strArgLetMsg); expect(() => test.letStrArg(true)).toThrow(strArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.letStrArg({}), strArgLetMsg); expect(() => test.letStrArg({})).toThrow(strArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.letStrArg([]), strArgLetMsg); expect(() => test.letStrArg([])).toThrow(strArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.letStrArg(), ''); expect(test.letStrArg()).toEqual('');
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.letStrArg(undefined), ''); expect(test.letStrArg(undefined)).toEqual('');
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.letStrArg(null), ''); expect(test.letStrArg(null)).toEqual('');
}); });
it('accepts a string', () => { it('accepts a string', () => {
assert.strictEqual(test.letStrArg('1abc'), '1abc'); expect(test.letStrArg('1abc')).toEqual('1abc');
}); });
}); });
describe('addon-tools.hpp: USE_STR_ARG', () => { describe('addon-tools.hpp: USE_STR_ARG', () => {
it('exports useStrArg', () => { it('exports useStrArg', () => {
assert.strictEqual(typeof test.useStrArg, 'function'); expect(typeof test.useStrArg).toBe('function');
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.useStrArg(1), strArgLetMsg); expect(() => test.useStrArg(1)).toThrow(strArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.useStrArg(true), strArgLetMsg); expect(() => test.useStrArg(true)).toThrow(strArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.useStrArg({}), strArgLetMsg); expect(() => test.useStrArg({})).toThrow(strArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.useStrArg([]), strArgLetMsg); expect(() => test.useStrArg([])).toThrow(strArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.useStrArg(), 'default'); expect(test.useStrArg()).toEqual('default');
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.useStrArg(undefined), 'default'); expect(test.useStrArg(undefined)).toEqual('default');
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.useStrArg(null), 'default'); expect(test.useStrArg(null)).toEqual('default');
}); });
it('accepts a string', () => { it('accepts a string', () => {
assert.strictEqual(test.useStrArg('1abc'), '1abc'); expect(test.useStrArg('1abc')).toEqual('1abc');
}); });
}); });

View File

@ -1,100 +1,96 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const test = require('./build/Release/test.node'); const test = require('./build/Release/test.node');
const uintArgMsg = { message: 'Argument 0 must be of type `Uint32`' }; const uintArgMsg = 'Argument 0 must be of type `Uint32`';
const uintArgLetMsg = { message: 'Argument 0 must be of type `Uint32` or be `null`/`undefined`' };
describe('AT / HPP / REQ_UINT_ARG, REQ_UINT32_ARG', () => { describe('AT / addon-tools.hpp / REQ_UINT_ARG, REQ_UINT32_ARG', () => {
it('exports reqUintArg', () => { it('exports reqUintArg', () => {
assert.strictEqual(typeof test.reqUintArg, 'function'); expect(typeof test.reqUintArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqUintArg(), uintArgMsg); expect(() => test.reqUintArg()).toThrow(uintArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqUintArg(undefined), uintArgMsg); expect(() => test.reqUintArg(undefined)).toThrow(uintArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqUintArg(null), uintArgMsg); expect(() => test.reqUintArg(null)).toThrow(uintArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqUintArg('1'), uintArgMsg); expect(() => test.reqUintArg('1')).toThrow(uintArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqUintArg(true), uintArgMsg); expect(() => test.reqUintArg(true)).toThrow(uintArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqUintArg({}), uintArgMsg); expect(() => test.reqUintArg({})).toThrow(uintArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.reqUintArg([]), uintArgMsg); expect(() => test.reqUintArg([])).toThrow(uintArgMsg);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.reqUintArg(55), 55); expect(test.reqUintArg(55)).toEqual(55);
}); });
}); });
describe('addon-tools.hpp: LET_UINT_ARG / LET_UINT32_ARG', () => { describe('addon-tools.hpp: LET_UINT_ARG / LET_UINT32_ARG', () => {
it('exports letUintArg', () => { it('exports letUintArg', () => {
assert.strictEqual(typeof test.letUintArg, 'function'); expect(typeof test.letUintArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.letUintArg('1'), uintArgLetMsg); expect(() => test.letUintArg('1')).toThrow(uintArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.letUintArg(true), uintArgLetMsg); expect(() => test.letUintArg(true)).toThrow(uintArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.letUintArg({}), uintArgLetMsg); expect(() => test.letUintArg({})).toThrow(uintArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.letUintArg([]), uintArgLetMsg); expect(() => test.letUintArg([])).toThrow(uintArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.letUintArg(), 0); expect(test.letUintArg()).toEqual(0);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.letUintArg(undefined), 0); expect(test.letUintArg(undefined)).toEqual(0);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.letUintArg(null), 0); expect(test.letUintArg(null)).toEqual(0);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.letUintArg(55), 55); expect(test.letUintArg(55)).toEqual(55);
}); });
}); });
describe('addon-tools.hpp: USE_UINT_ARG / USE_UINT32_ARG', () => { describe('addon-tools.hpp: USE_UINT_ARG / USE_UINT32_ARG', () => {
it('exports useUintArg', () => { it('exports useUintArg', () => {
assert.strictEqual(typeof test.useUintArg, 'function'); expect(typeof test.useUintArg).toBe('function');
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.useUintArg('1'), uintArgLetMsg); expect(() => test.useUintArg('1')).toThrow(uintArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.useUintArg(true), uintArgLetMsg); expect(() => test.useUintArg(true)).toThrow(uintArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.useUintArg({}), uintArgLetMsg); expect(() => test.useUintArg({})).toThrow(uintArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.useUintArg([]), uintArgLetMsg); expect(() => test.useUintArg([])).toThrow(uintArgMsg);
}); });
it('accepts an empty arg', () => { it('accepts an empty arg', () => {
assert.strictEqual(test.useUintArg(), 10); expect(test.useUintArg()).toEqual(10);
}); });
it('accepts undefined', () => { it('accepts undefined', () => {
assert.strictEqual(test.useUintArg(undefined), 10); expect(test.useUintArg(undefined)).toEqual(10);
}); });
it('accepts null', () => { it('accepts null', () => {
assert.strictEqual(test.useUintArg(null), 10); expect(test.useUintArg(null)).toEqual(10);
}); });
it('accepts a number', () => { it('accepts a number', () => {
assert.strictEqual(test.useUintArg(55), 55); expect(test.useUintArg(55)).toEqual(55);
}); });
}); });

View File

@ -1,211 +1,205 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const test = require('./build/Release/test.node'); const test = require('./build/Release/test.node');
describe('AT / HPP / Function arguments', () => { describe('AT / addon-tools.hpp / Function arguments', () => {
const arg3Msg = { message: 'Expected at least 3 arguments' };
describe('REQ_ARGS', () => { describe('REQ_ARGS', () => {
it('exports reqArgs3', () => { it('exports reqArgs3', () => {
assert.strictEqual(typeof test.reqArgs3, 'function'); expect(typeof test.reqArgs3).toBe('function');
}); });
it('throws if no args passed', () => { it('throws if no args passed', () => {
assert.throws(() => test.reqArgs3(), arg3Msg); expect(() => test.reqArgs3()).toThrow('Expected at least 3 arguments');
}); });
it('throws if 1 arg passed', () => { it('throws if 1 arg passed', () => {
assert.throws(() => test.reqArgs3(1), arg3Msg); expect(() => test.reqArgs3(1)).toThrow('Expected at least 3 arguments');
}); });
it('returns true if 3 args passed', () => { it('returns true if 3 args passed', () => {
assert.ok(test.reqArgs3(1, 2, 3)); expect(test.reqArgs3(1, 2, 3)).toEqual(true);
}); });
it('returns true if 5 args passed', () => { it('returns true if 5 args passed', () => {
assert.ok(test.reqArgs3(1, 2, 3, 4, 5)); expect(test.reqArgs3(1, 2, 3, 4, 5)).toEqual(true);
}); });
}); });
describe('IS_ARG_EMPTY', () => { describe('IS_ARG_EMPTY', () => {
it('exports isArg0Empty', () => { it('exports isArg0Empty', () => {
assert.strictEqual(typeof test.isArg0Empty, 'function'); expect(typeof test.isArg0Empty).toBe('function');
}); });
it('returns true for absent arg', () => { it('returns true for absent arg', () => {
assert.ok(test.isArg0Empty()); expect(test.isArg0Empty()).toEqual(true);
}); });
it('returns true for undefined arg', () => { it('returns true for undefined arg', () => {
assert.ok(test.isArg0Empty(undefined)); expect(test.isArg0Empty(undefined)).toEqual(true);
}); });
it('returns true for null arg', () => { it('returns true for null arg', () => {
assert.ok(test.isArg0Empty(null)); expect(test.isArg0Empty(null)).toEqual(true);
}); });
it('returns false for non-empty value', () => { it('returns false for non-empty value', () => {
assert.strictEqual(test.isArg0Empty(1), false); expect(test.isArg0Empty(1)).toEqual(false);
}); });
}); });
// ------------------------------ FUN_ARG // ------------------------------ FUN_ARG
const funArgMsg = { message: 'Argument 0 must be of type `Function`' }; const funArgMsg = 'Argument 0 must be of type `Function`';
describe('REQ_FUN_ARG', () => { describe('REQ_FUN_ARG', () => {
it('exports reqFunArg', () => { it('exports reqFunArg', () => {
assert.strictEqual(typeof test.reqFunArg, 'function'); expect(typeof test.reqFunArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqFunArg(), funArgMsg); expect(() => test.reqFunArg()).toThrow(funArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqFunArg(undefined), funArgMsg); expect(() => test.reqFunArg(undefined)).toThrow(funArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqFunArg(null), funArgMsg); expect(() => test.reqFunArg(null)).toThrow(funArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqFunArg('1'), funArgMsg); expect(() => test.reqFunArg('1')).toThrow(funArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.reqFunArg(1), funArgMsg); expect(() => test.reqFunArg(1)).toThrow(funArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqFunArg(true), funArgMsg); expect(() => test.reqFunArg(true)).toThrow(funArgMsg);
}); });
it('throws if arg was passed a pointer', () => { it('throws if arg was passed a pointer', () => {
assert.throws(() => test.reqFunArg(test.retExt()), funArgMsg); expect(() => test.reqFunArg(test.retExt())).toThrow(funArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqFunArg({}), funArgMsg); expect(() => test.reqFunArg({})).toThrow(funArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.reqFunArg([]), funArgMsg); expect(() => test.reqFunArg([])).toThrow(funArgMsg);
}); });
it('accepts a function', () => { it('accepts a function', () => {
assert.strictEqual(typeof test.reqFunArg(() => {}), 'function'); expect(typeof test.reqFunArg(() => {})).toBe('function');
}); });
}); });
// ------------------------------ ARRV_ARG // ------------------------------ ARRV_ARG
const arrvArgMsg = { message: 'Argument 0 must be of type `ArrayBuffer`' }; const arrvArgMsg = 'Argument 0 must be of type `ArrayBuffer`';
describe('REQ_ARRV_ARG', () => { describe('REQ_ARRV_ARG', () => {
it('exports reqArrvArg', () => { it('exports reqArrvArg', () => {
assert.strictEqual(typeof test.reqArrvArg, 'function'); expect(typeof test.reqArrvArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqArrvArg(), arrvArgMsg); expect(() => test.reqArrvArg()).toThrow(arrvArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqArrvArg(undefined), arrvArgMsg); expect(() => test.reqArrvArg(undefined)).toThrow(arrvArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqArrvArg(null), arrvArgMsg); expect(() => test.reqArrvArg(null)).toThrow(arrvArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqArrvArg('1'), arrvArgMsg); expect(() => test.reqArrvArg('1')).toThrow(arrvArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.reqArrvArg(1), arrvArgMsg); expect(() => test.reqArrvArg(1)).toThrow(arrvArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqArrvArg(true), arrvArgMsg); expect(() => test.reqArrvArg(true)).toThrow(arrvArgMsg);
}); });
it('throws if arg was passed a pointer', () => { it('throws if arg was passed a pointer', () => {
assert.throws(() => test.reqArrvArg(test.retExt()), arrvArgMsg); expect(() => test.reqArrvArg(test.retExt())).toThrow(arrvArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqArrvArg({}), arrvArgMsg); expect(() => test.reqArrvArg({})).toThrow(arrvArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.reqArrvArg([]), arrvArgMsg); expect(() => test.reqArrvArg([])).toThrow(arrvArgMsg);
}); });
it('accepts an array buffer', () => { it('accepts an array buffer', () => {
const { buffer } = new Uint8Array([1, 2, 3]); const { buffer } = new Uint8Array([1, 2, 3]);
assert.strictEqual(test.reqArrvArg(buffer), buffer); expect(test.reqArrvArg(buffer)).toEqual(buffer);
}); });
}); });
// ------------------------------ BUF_ARG // ------------------------------ BUF_ARG
const bufArgMsg = { message: 'Argument 0 must be of type `Buffer`' }; const bufArgMsg = 'Argument 0 must be of type `Buffer`';
describe('REQ_BUF_ARG', () => { describe('REQ_BUF_ARG', () => {
it('exports reqBufArg', () => { it('exports reqBufArg', () => {
assert.strictEqual(typeof test.reqBufArg, 'function'); expect(typeof test.reqBufArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqBufArg(), bufArgMsg); expect(() => test.reqBufArg()).toThrow(bufArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqBufArg(undefined), bufArgMsg); expect(() => test.reqBufArg(undefined)).toThrow(bufArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqBufArg(null), bufArgMsg); expect(() => test.reqBufArg(null)).toThrow(bufArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqBufArg('1'), bufArgMsg); expect(() => test.reqBufArg('1')).toThrow(bufArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.reqBufArg(1), bufArgMsg); expect(() => test.reqBufArg(1)).toThrow(bufArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqBufArg(true), bufArgMsg); expect(() => test.reqBufArg(true)).toThrow(bufArgMsg);
}); });
it('throws if arg was passed a pointer', () => { it('throws if arg was passed a pointer', () => {
assert.throws(() => test.reqBufArg(test.retExt()), bufArgMsg); expect(() => test.reqBufArg(test.retExt())).toThrow(bufArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqBufArg({}), bufArgMsg); expect(() => test.reqBufArg({})).toThrow(bufArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.reqBufArg([]), bufArgMsg); expect(() => test.reqBufArg([])).toThrow(bufArgMsg);
}); });
it('accepts a buffer', () => { it('accepts a buffer', () => {
const buffer = Buffer.from([1, 2, 3]); const buffer = Buffer.from([1, 2, 3]);
assert.strictEqual(test.reqBufArg(buffer), buffer); expect(test.reqBufArg(buffer)).toEqual(buffer);
}); });
}); });
// ------------------------------ TYPED_ARRAY_ARG // ------------------------------ TYPED_ARRAY_ARG
const typedArgMsg = { message: 'Argument 0 must be of type `TypedArray`' }; const typedArgMsg = 'Argument 0 must be of type `TypedArray`';
describe('REQ_TYPED_ARRAY_ARG', () => { describe('REQ_TYPED_ARRAY_ARG', () => {
it('exports reqTypedArg', () => { it('exports reqTypedArg', () => {
assert.strictEqual(typeof test.reqTypedArg, 'function'); expect(typeof test.reqTypedArg).toBe('function');
}); });
it('throws if arg was not passed', () => { it('throws if arg was not passed', () => {
assert.throws(() => test.reqTypedArg(), typedArgMsg); expect(() => test.reqTypedArg()).toThrow(typedArgMsg);
}); });
it('throws if arg was passed undefined', () => { it('throws if arg was passed undefined', () => {
assert.throws(() => test.reqTypedArg(undefined), typedArgMsg); expect(() => test.reqTypedArg(undefined)).toThrow(typedArgMsg);
}); });
it('throws if arg was passed null', () => { it('throws if arg was passed null', () => {
assert.throws(() => test.reqTypedArg(null), typedArgMsg); expect(() => test.reqTypedArg(null)).toThrow(typedArgMsg);
}); });
it('throws if arg was passed a string', () => { it('throws if arg was passed a string', () => {
assert.throws(() => test.reqTypedArg('1'), typedArgMsg); expect(() => test.reqTypedArg('1')).toThrow(typedArgMsg);
}); });
it('throws if arg was passed a number', () => { it('throws if arg was passed a number', () => {
assert.throws(() => test.reqTypedArg(1), typedArgMsg); expect(() => test.reqTypedArg(1)).toThrow(typedArgMsg);
}); });
it('throws if arg was passed a boolean', () => { it('throws if arg was passed a boolean', () => {
assert.throws(() => test.reqTypedArg(true), typedArgMsg); expect(() => test.reqTypedArg(true)).toThrow(typedArgMsg);
}); });
it('throws if arg was passed a pointer', () => { it('throws if arg was passed a pointer', () => {
assert.throws(() => test.reqTypedArg(test.retExt()), typedArgMsg); expect(() => test.reqTypedArg(test.retExt())).toThrow(typedArgMsg);
}); });
it('throws if arg was passed an object', () => { it('throws if arg was passed an object', () => {
assert.throws(() => test.reqTypedArg({}), typedArgMsg); expect(() => test.reqTypedArg({})).toThrow(typedArgMsg);
}); });
it('throws if arg was passed an array', () => { it('throws if arg was passed an array', () => {
assert.throws(() => test.reqTypedArg([]), typedArgMsg); expect(() => test.reqTypedArg([])).toThrow(typedArgMsg);
}); });
it('accepts a typed array', () => { it('accepts a typed array', () => {
const typed = new Uint8Array([1, 2, 3]); const typed = new Uint8Array([1, 2, 3]);
assert.strictEqual(test.reqTypedArg(typed), typed); expect(test.reqTypedArg(typed)).toEqual(typed);
}); });
}); });
}); });

View File

@ -1,24 +0,0 @@
'use strict';
const { copy, exists } = require('./files');
const cpcpplint = async () => {
const cpplintDest = `${process.cwd()}/CPPLINT.cfg`.replace(/\\/g, '/');
const cpplintSrc = `${__dirname}/CPPLINT.cfg`.replace(/\\/g, '/');
if (!await exists(cpplintSrc) ) {
console.error('Error. File "CPPLINT.cfg" not found.');
return;
}
if (await exists(cpplintDest) ) {
console.warn('Warning. Dest "CPPLINT.cfg" exists and will be overwritten.');
}
await copy(cpplintSrc, cpplintDest);
console.log(`"CPPLINT.cfg" was copied to "${cpplintDest}".`);
};
module.exports = { cpcpplint };

View File

@ -5,7 +5,6 @@ module.exports = Object.assign(
{}, {},
require('./action-pack'), require('./action-pack'),
require('./cpbin'), require('./cpbin'),
require('./cpcpplint'),
require('./download'), require('./download'),
require('./files'), require('./files'),
require('./install'), require('./install'),

View File

@ -1,8 +1,5 @@
'use strict'; 'use strict';
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');
const utils = require('.'); const utils = require('.');
@ -16,7 +13,7 @@ describe('AT / utils', () => {
methods.forEach((name) => { methods.forEach((name) => {
it(`exports the "${name}" function`, () => { it(`exports the "${name}" function`, () => {
assert.strictEqual(typeof utils[name], 'function'); expect(typeof utils[name]).toBe('function');
}); });
}); });
}); });