Skip to content

Commit

Permalink
Move and improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raub committed Oct 27, 2024
1 parent 0f80849 commit 1aa09d9
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.lock-wscript
.DS_Store
.project
.DS_Store
node_modules/
test-addon/build/
bin-*/
*.log
17 changes: 7 additions & 10 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ For **GYP**, the include directory is accessible with:
],
```

For more examples, see [code snippets here](snippets.md).


### Logging
## Logging

Console logging and "global" logging helpers for C++ side are available:

Expand All @@ -48,13 +46,6 @@ See JS Utils section in [README](/README.md).
```
### ES5 Classes
Addon Tools provides C++ macro helpers for ES5 Classes (`function`-based).
See the [class-wrapping doc here](class-wrapping.md).
### Function Helpers
Most of the helpers work within functions, where `Napi::CallbackInfo info` is
Expand Down Expand Up @@ -242,3 +233,9 @@ calls `getArrayData` or `getArrayData` on it. Otherwise, if
`value.data` is a `TypedArray|Buffer`,
calls `getArrayData` or `getArrayData` on it.
Returns `nullptr` in other cases.


### ES5 Classes

Addon Tools provides C++ macro helpers for ES5 Classes (`function`-based).
See the [class-wrapping doc here](class-wrapping.md).
4 changes: 2 additions & 2 deletions doc/class-wrapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ and on C++ side there is `inheritEs5` function.

## Class Declaration

```
```cpp
class ClassName {
DECLARE_ES5_CLASS(ClassName, JSClassName);

Expand Down Expand Up @@ -48,7 +48,7 @@ the second is the name of the setter to be created.
## Class Implementation
```
```cpp
IMPLEMENT_ES5_CLASS(ClassName);
// Fill the properties and export the class
Expand Down
81 changes: 0 additions & 81 deletions doc/snippets.md

This file was deleted.

23 changes: 21 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,21 +371,40 @@ declare module "addon-tools-raub" {
type TGlobalLoggerLevel = keyof TGlobalLoggerMethods;

type TGlobalLoggerOpts = TGlobalLoggerMethods & Readonly<{
/** Globally available name for a new logger */
name: string,
}>;

type TGlobalLogger = TGlobalLoggerMethods & Readonly<{
/** Replace a logger channel in an existing logger */
replace: (level: string, fn: TLoggerFn) => void,
}>;

/**
* Create a named global logger
*
* Copy a folder with all the contained files
*
* It will be also available from
* `global.AddonTools.log(name, level, arg1, arg2, ...);`
*/
export const createLogger: (opts: TGlobalLoggerOpts) => TGlobalLogger;

/**
* Set logger level or `null` to turn off
*/
export const setLevel: (level: TGlobalLoggerLevel | null) => void;

/**
* Get logger level
*/
export const getLevel: () => (TGlobalLoggerLevel | null);

/**
* Get an object containing all registered loggers
*/
export const getLoggers: () => Readonly<Record<string, TGlobalLogger>>

/**
* Get a logger by name, returns null if not found
*/
export const getLogger: () => (TGlobalLogger | null)
}
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
],
"files": [
"include",
"utils.js",
"utils.d.ts",
"index.js",
"index.d.ts",
"utils",
"LICENSE",
"package.json",
"README.md"
"package.json"
],
"engines": {
"node": ">=22.9.0",
Expand Down
22 changes: 22 additions & 0 deletions tests/download.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const assert = require('node:assert').strict;
const { describe, it } = require('node:test');

const { download } = require('..');


const url = 'https://raw.githubusercontent.com/node-3d/image-raub/refs/tags/4.3.0/test/freeimage.jpg';


describe('AT / Download', async () => {
const data = await download(url);

it('data is Buffer', () => {
assert.strictEqual(data.constructor, Buffer);
});

it('downloaded byte count is correct', async () => {
assert.strictEqual(data.length, 7972);
});
});
4 changes: 2 additions & 2 deletions include.test.js → tests/include.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');

const tools = require('.');
const tools = require('..');


describe('AT / include', () => {
describe('AT / Include', () => {
const stringMethods = ['getBin', 'getPlatform', 'getInclude'];

stringMethods.forEach((name) => {
Expand Down
29 changes: 29 additions & 0 deletions tests/install.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const assert = require('node:assert').strict;
const { describe, it } = require('node:test');

const { install, exists, getBin } = require('..');


const prefix = 'https://github.com/node-3d/segfault-raub/releases/download';
const tag = '2.3.0';


describe('AT / Install', async () => {
const status = await install(`${prefix}/${tag}`);

it('status is true', () => {
assert.strictEqual(status, true);
});

it('platform folder exists', async () => {
const isFolderCreated = await exists(`${__dirname}/../${getBin()}`);
assert.strictEqual(isFolderCreated, true);
});

it('platform binary exists', async () => {
const isAddonAvailable = await exists(`${__dirname}/../${getBin()}/segfault.node`);
assert.strictEqual(isAddonAvailable, true);
});
});
2 changes: 1 addition & 1 deletion logger.test.js → tests/logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');

const utils = require('.');
const utils = require('..');

describe('AT / Logger', () => {
let logged = '';
Expand Down
2 changes: 1 addition & 1 deletion utils.test.js → tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const assert = require('node:assert').strict;
const { describe, it } = require('node:test');

const utils = require('.');
const utils = require('..');


describe('AT / Util Exports', () => {
Expand Down

0 comments on commit 1aa09d9

Please sign in to comment.