Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
chore: add a unit test for addArchiveSize (#1308)
Browse files Browse the repository at this point in the history
* test: add a unit test for addArchiveSize

* Apply suggestions from code review

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>

* test: remove join

* chore: rename tsc watch script

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
  • Loading branch information
khendrikse and eduardoboucas committed Jan 12, 2023
1 parent 977a39d commit de48712
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"prepublishOnly": "npm ci && npm test",
"prepack": "npm run build",
"build": "tsc",
"build:dev": "tsc -w",
"benchmark": "./benchmarks/run.sh",
"format": "run-s build format:check-fix:*",
"format:ci": "run-s build format:check:*",
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/archive-size/normal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const handler = async (event, context) => {
return {
statusCode: 200,
body: `hello world!`,
};
};

export { handler };
Binary file added tests/fixtures/archive-size/normal.zip
Binary file not shown.
29 changes: 29 additions & 0 deletions tests/unit/utils/archive_size.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { resolve } from 'path'

import { describe, expect, test } from 'vitest'

import { FunctionArchive } from '../../../src/function.js'
import { addArchiveSize } from '../../../src/utils/archive_size.js'
import { FIXTURES_DIR } from '../../helpers/main.js'

describe('addArchiveSize', () => {
test('adds the archive size of the file at `path` if it is a ZIP archive', async () => {
const functionArchive = {
path: resolve(FIXTURES_DIR, 'archive-size', 'normal.zip'),
} as FunctionArchive

const result = await addArchiveSize(functionArchive)

expect(result.size).toBe(1098)
})

test('does not add the archive size of the file at `path` if it is not a ZIP archive', async () => {
const functionArchive = {
path: resolve(FIXTURES_DIR, 'archive-size', 'normal.js'),
} as FunctionArchive

const result = await addArchiveSize(functionArchive)

expect(result.size).toBeUndefined()
})
})

1 comment on commit de48712

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

  • largeDepsEsbuild: 2s
  • largeDepsNft: 7.6s
  • largeDepsZisi: 14.9s

Please sign in to comment.