Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
pull-requests: write

strategy:
fail-fast: false
matrix:
node-version: [18, "lts/*", "latest"]

Expand Down
17 changes: 0 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"coveralls": "^3.1.0",
"eslint": "^8.0.0",
"mocha": "^11.0.0",
"mock-fs": "^5.5.0",
"nyc": "^17.0.0",
"supports-color": "^8.1.1"
},
Expand Down
70 changes: 37 additions & 33 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,38 @@
'use strict';

const assert = require("assert");
const mockFs = require("mock-fs");
const fs = require("fs");
const path = require("path");
const tmp = require("tmp");
tmp.setGracefulCleanup();

const config = require("../lib/config");

const CONFIG_FILE = ".sizewatcher.yml";

// switch into a clean new temporary directory, optionally with a config file
function mockConfig(content) {
const tmpDir = tmp.dirSync({unsafeCleanup: true}).name;
process.chdir(tmpDir);
if (content !== undefined) {
fs.writeFileSync(path.join(tmpDir, CONFIG_FILE), content);
}
}

describe("config", function() {

let originalCwd;

beforeEach(function() {
originalCwd = process.cwd();
});

afterEach(function() {
mockFs.restore();
process.chdir(originalCwd);
});

it("loads default config if no config file exists", function() {
mockFs();
mockConfig();
const cfg = config.reload();
assert.strictEqual(typeof cfg, "object");
assert.deepStrictEqual(cfg.limits, {
Expand All @@ -37,9 +58,7 @@ describe("config", function() {
});

it("loads config file that is empty", function() {
mockFs({
".sizewatcher.yml": ""
});
mockConfig("");
const cfg = config.reload();
assert.strictEqual(typeof cfg, "object");
assert.deepStrictEqual(cfg.limits, {
Expand All @@ -53,13 +72,10 @@ describe("config", function() {
});

it("loads config file with percentage limits", function() {
mockFs({
".sizewatcher.yml":
`
mockConfig(`
limits:
fail: 42%
`
});
`);
const cfg = config.reload();
assert.strictEqual(typeof cfg, "object");
assert.deepStrictEqual(cfg.limits, {
Expand All @@ -70,15 +86,12 @@ limits:
});

it("loads config file with integer limits", function() {
mockFs({
".sizewatcher.yml":
`
mockConfig(`
limits:
fail: 1000
warn: 100
ok: 50
`
});
`);
const cfg = config.reload();
assert.strictEqual(typeof cfg, "object");
assert.deepStrictEqual(cfg.limits, {
Expand All @@ -89,22 +102,19 @@ limits:
});

it("loads config file with reportStatus", function() {
mockFs({
".sizewatcher.yml":
`
mockConfig(`
report:
githubComment: false
githubStatus: true
`
});
`);
const cfg = config.reload();
assert.strictEqual(typeof cfg, "object");
assert.strictEqual(cfg.report.githubComment, false);
assert.strictEqual(cfg.report.githubStatus, true);
});

it("returns default config in asYaml() if no config file exists", function() {
mockFs();
mockConfig();
config.reload();
const yaml = config.asYaml();
assert.strictEqual(yaml, `limits:
Expand All @@ -119,15 +129,12 @@ comparators: {}
});

it("handles a single custom comparators", function() {
mockFs({
".sizewatcher.yml":
`
mockConfig(`
comparators:
custom:
name: mine
path: build/file
`
});
`);
const cfg = config.reload();
assert.strictEqual(typeof cfg, "object");
assert.strictEqual(typeof cfg.comparators.custom, "object");
Expand All @@ -136,21 +143,18 @@ comparators:
});

it("handles a multiple custom comparators", function() {
mockFs({
".sizewatcher.yml":
`
mockConfig(`
comparators:
custom:
- name: mine
path: build/file
- path: build/file2
`
});
`);
const cfg = config.reload();
assert.strictEqual(typeof cfg, "object");
assert.ok(Array.isArray(cfg.comparators.custom));
assert.strictEqual(cfg.comparators.custom[0].name, "mine");
assert.strictEqual(cfg.comparators.custom[0].path, "build/file");
assert.strictEqual(cfg.comparators.custom[1].path, "build/file2");
});
});
});
Loading