Skip to content

Commit

Permalink
Add tests and update build generation
Browse files Browse the repository at this point in the history
  • Loading branch information
andresz1 committed Mar 16, 2020
1 parent 865bbe6 commit b824cd8
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 24 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "size"
on:
pull_request:
branches:
- master
jobs:
size:
runs-on: ubuntu-latest
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v1
- run: |
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
- uses: ./
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
18 changes: 3 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
name: "test"
on:
push:
branches:
- master
pull_request:
branches:
- master
on: [push, pull_request]
jobs:
test:
size:
runs-on: ubuntu-latest
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v1
- run: |
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
- uses: ./
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- run: npm run test
14 changes: 8 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// @ts-nocheck

module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
moduleFileExtensions: ["js", "ts"],
testEnvironment: "node",
testMatch: ["**/*.spec.ts"],
testRunner: "jest-circus/runner",
transform: {
'^.+\\.ts$': 'ts-jest'
"^.+\\.ts$": "ts-jest"
},
verbose: true
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "eslint src/**/*.ts",
"test": "jest",
"build": "ncc build src/main.ts -o dist",
"size": "size-limit --json"
"size": "npm run build && size-limit"
},
"size-limit": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Git {

await exec("npm install");
await exec("npm run build");
const status = await exec("npx size-limit --json", [], {
const status = await exec("npm run size -- --json", [], {
windowsVerbatimArguments: true,
ignoreReturnCode: true,
listeners: {
Expand Down
58 changes: 58 additions & 0 deletions src/SizeLimit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import SizeLimit from "./SizeLimit";

describe("SizeLimit", () => {
test("should parse size-limit output properly", () => {
const limit = new SizeLimit();
const output = JSON.stringify([
{
name: "dist/index.js",
passed: true,
size: 110894,
running: 0.10210999999999999,
loading: 2.1658984375
}
]);

expect(limit.parseResults(output)).toEqual({
"dist/index.js": {
loading: 2.1658984375,
name: "dist/index.js",
running: 0.10210999999999999,
size: 110894,
total: 2.2680084375000003
}
});
});

test("should format size-limit results properly", () => {
const limit = new SizeLimit();
const base = {
"dist/index.js": {
name: "dist/index.js",
size: 110894,
running: 0.10210999999999999,
loading: 2.1658984375,
total: 2.2680084375000003
}
};
const current = {
"dist/index.js": {
name: "dist/index.js",
size: 100894,
running: 0.20210999999999999,
loading: 2.5658984375,
total: 2.7680084375000003
}
};

expect(limit.formatResults(base, current)).toEqual([
[
"dist/index.js",
"98.53 KB (-9.92% 🔽)",
"2.6 s (+15.59% 🔺)",
"203 ms (+49.48% 🔺)",
"2.8 s"
]
]);
});
});
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const TABLE_HEADER = [
"Running time (snapdragon)",
"Total time"
];
const SIZE_LIMIT_URL = "https://github.com/ai/size-limit";

async function run() {
try {
Expand All @@ -34,7 +35,7 @@ async function run() {
const number = context.payload.pull_request.number;
const event = status > 0 ? "REQUEST_CHANGES" : "COMMENT";
const body = [
"## [size-limit](https://github.com/ai/size-limit) report",
`## [size-limit](${SIZE_LIMIT_URL}) report`,
table([TABLE_HEADER, ...limit.formatResults(base, current)])
].join("\r\n");

Expand Down

0 comments on commit b824cd8

Please sign in to comment.