Skip to content

Commit e3e7d0c

Browse files
committed
add package test
1 parent 895e22c commit e3e7d0c

6 files changed

Lines changed: 57 additions & 1 deletion

File tree

.github/workflows/js.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ jobs:
3434
- name: Live Tests (TS ESM)
3535
run: npm run ts-test-live
3636
- name: CJS test
37-
run: npm run test-cjs
37+
run: npm run test-cjs
38+
- name: Package test
39+
run: npm run package-test

.npmignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Initally ignore all files
2+
*
3+
4+
# Files to include
5+
!package.json
6+
!package-lock.json
7+
!LICENSE.txt
8+
!README.md
9+
10+
# Folders to include
11+
!src/**/*
12+
!dist/**/*
13+

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"codacy": "cat ./coverage/lcov.info | codacy-coverage -v",
3535
"codecov": "codecov",
3636
"bundle-cjs": "mkdir -p dist/cjs && rollup -c rollup.config.js",
37+
"package-test": "./tests/package.sh",
3738
"publishPackage": "sh publish.sh && git push && git push --tags && npm publish",
3839
"rollup-plugin-execute": "^1.1.1"
3940
},

tests/package-test/test-cjs.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const Binance = require('node-binance-api');
2+
3+
const client = new Binance()
4+
5+
async function main() {
6+
const ticker = await client.prices('BTCUSDT')
7+
console.log(ticker)
8+
}
9+
10+
main()

tests/package-test/test-esm.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Binance from 'node-binance-api'
2+
const client = new Binance()
3+
4+
async function main() {
5+
const ticker = await client.bookTickers('BTCUSDT')
6+
const res = ticker['BTCUSDT'];
7+
console.log(res)
8+
}
9+
10+
main()

tests/package.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
npm pack . --silent
4+
mv node-binance-api*.tgz ./tests/package-test/
5+
cd ./tests/package-test
6+
npm init -y > /dev/null
7+
npm install node-binance-api*.tgz
8+
node test-esm.mjs
9+
return_code=$?
10+
node test-cjs.cjs
11+
cjs_return_code=$?
12+
rm -rf node_modules node-binance-api*.tgz package-lock.json package.json
13+
14+
if [ $return_code -eq 0 ] && [ $cjs_return_code -eq 0 ]; then
15+
echo "Package test successful"
16+
exit 0
17+
else
18+
echo "Package test failed"
19+
exit 1
20+
fi

0 commit comments

Comments
 (0)