Test exports

This commit is contained in:
Dmitry Shirokov 2022-09-30 12:41:58 +10:00
parent 1966208bcb
commit efad3c3f0d
No known key found for this signature in database
GPG Key ID: 8497F81BB7F0B0C0
5 changed files with 59 additions and 0 deletions

View File

@ -23,3 +23,4 @@ jobs:
- run: npm i - run: npm i
- run: npm test - run: npm test
- run: npm run build - run: npm run build
- run: node .github/workflows/test-build.sh

22
.github/workflows/test-build.js vendored Normal file
View File

@ -0,0 +1,22 @@
const assert = require('assert');
const path = require('path');
const chardet = require(process.cwd());
assert(typeof chardet.analyse, 'function');
assert(typeof chardet.detect, 'function');
assert(typeof chardet.detectFile, 'function');
assert(typeof chardet.detectFileSync, 'function');
assert.deepStrictEqual(chardet.analyse(Buffer.from('This is a test')), [
{ confidence: 98, name: 'ISO-8859-1', lang: 'en' },
{ confidence: 98, name: 'ISO-8859-2', lang: 'hu' },
{ confidence: 10, name: 'UTF-8', lang: undefined },
{ confidence: 10, name: 'Shift_JIS', lang: 'ja' },
{ confidence: 10, name: 'Big5', lang: 'zh' },
{ confidence: 10, name: 'EUC-JP', lang: 'ja' },
{ confidence: 10, name: 'EUC-KR', lang: 'ko' },
{ confidence: 10, name: 'GB18030', lang: 'zh' },
]);
console.log(' > test-build.js OK');

6
.github/workflows/test-build.sh vendored Normal file
View File

@ -0,0 +1,6 @@
#!/bin/sh -ex
export PATH=$PATH:$(npm bin)
node ./.github/workflows/test-build.js
ts-node ./.github/workflows/test-build.ts

29
.github/workflows/test-build.ts vendored Normal file
View File

@ -0,0 +1,29 @@
import assert from 'assert';
import path from 'path';
const main = async () => {
const chardet = await import(process.cwd());
assert(typeof chardet.analyse, 'function');
assert(typeof chardet.detect, 'function');
assert(typeof chardet.detectFile, 'function');
assert(typeof chardet.detectFileSync, 'function');
assert.deepStrictEqual(chardet.analyse(Buffer.from('This is a test')), [
{ confidence: 98, name: 'ISO-8859-1', lang: 'en' },
{ confidence: 98, name: 'ISO-8859-2', lang: 'hu' },
{ confidence: 10, name: 'UTF-8', lang: undefined },
{ confidence: 10, name: 'Shift_JIS', lang: 'ja' },
{ confidence: 10, name: 'Big5', lang: 'zh' },
{ confidence: 10, name: 'EUC-JP', lang: 'ja' },
{ confidence: 10, name: 'EUC-KR', lang: 'ko' },
{ confidence: 10, name: 'GB18030', lang: 'zh' },
]);
};
main()
.then(() => console.log(' > test-build.ts OK'))
.catch((err) => {
console.error(err);
process.exit(1);
});

View File

@ -39,6 +39,7 @@
"prettier": "^2.1.2", "prettier": "^2.1.2",
"semantic-release": "^17.1.2", "semantic-release": "^17.1.2",
"ts-jest": "^26.4.0", "ts-jest": "^26.4.0",
"ts-node": "^10.9.1",
"typescript": "^4.8.4" "typescript": "^4.8.4"
}, },
"keywords": [ "keywords": [