Skip to content

Commit

Permalink
test: add a test case for compress file into Buffer (#104)
Browse files Browse the repository at this point in the history
closes #103

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Chores**
- Removed the `workflow_dispatch` trigger from Node.js workflow
configurations.

- **Tests**
	- Added a new test for gzip compression functionality.
- Reorganized test scripts in `package.json` for better clarity and
execution.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Apr 23, 2024
1 parent 1112123 commit 7043a9c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ on:
pull_request:
branches: [ master ]

workflow_dispatch: {}

jobs:
Job:
name: Node.js
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ on:
push:
branches: [ master ]

workflow_dispatch: {}

jobs:
release:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
with:
checkTest: false
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"main": "index.js",
"scripts": {
"contributor": "git-contributor",
"ts-test": "tsc -p ./test/fixtures/types/tsconfig.json",
"test": "egg-bin test --ts false && npm run ts-test",
"test:ts": "tsc -p ./test/fixtures/types/tsconfig.json",
"test:js": "egg-bin test --ts false",
"test": "npm run test:js && npm run test:ts",
"cov": "egg-bin cov --ts false",
"lint-fix": "eslint . --fix",
"lint": "eslint .",
"ci": "npm run lint && npm run ts-test && npm run cov"
"ci": "npm run lint && npm run test:ts && npm run cov"
},
"repository": {
"type": "git",
Expand Down
15 changes: 13 additions & 2 deletions test/gzip/file_stream.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const fs = require('fs');
const os = require('os');
const path = require('path');
Expand Down Expand Up @@ -36,6 +34,19 @@ describe('test/gzip/file_stream.test.js', () => {
});
});

it('should compress file into Buffer', async () => {
const sourceFile = path.join(__dirname, '..', 'fixtures', 'xx.log');
const gzipStream = new compressing.gzip.FileStream({ source: sourceFile });
const gzipChunks = [];
for await (const chunk of gzipStream) {
gzipChunks.push(chunk);
}

const destFile = path.join(os.tmpdir(), uuid.v4() + '.log.gz');
await fs.promises.writeFile(destFile, Buffer.concat(gzipChunks));
console.log(destFile);
});

it('should compress buffer', done => {
const sourceFile = path.join(__dirname, '..', 'fixtures', 'xx.log');
const sourceBuffer = fs.readFileSync(sourceFile);
Expand Down

0 comments on commit 7043a9c

Please sign in to comment.