diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index bc5eaf2..264a171 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -15,6 +15,7 @@ jobs: pull-requests: write strategy: + fail-fast: false matrix: node-version: [18, "lts/*", "latest"] diff --git a/package-lock.json b/package-lock.json index db4445f..0f9555e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,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" } @@ -3691,16 +3690,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/mock-fs": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/mock-fs/-/mock-fs-5.5.0.tgz", - "integrity": "sha512-d/P1M/RacgM3dB0sJ8rjeRNXxtapkPCUnMGmIN0ixJ16F/E4GUZCvWcSGfWGz8eaXYvn1s9baUwNjI4LOPEjiA==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=12.0.0" - } - }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -8089,12 +8078,6 @@ } } }, - "mock-fs": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/mock-fs/-/mock-fs-5.5.0.tgz", - "integrity": "sha512-d/P1M/RacgM3dB0sJ8rjeRNXxtapkPCUnMGmIN0ixJ16F/E4GUZCvWcSGfWGz8eaXYvn1s9baUwNjI4LOPEjiA==", - "dev": true - }, "ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", diff --git a/package.json b/package.json index 2315f37..845876d 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/config.test.js b/test/config.test.js index 14b5ee4..fc89f29 100644 --- a/test/config.test.js +++ b/test/config.test.js @@ -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, { @@ -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, { @@ -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, { @@ -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, { @@ -89,14 +102,11 @@ 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); @@ -104,7 +114,7 @@ report: }); it("returns default config in asYaml() if no config file exists", function() { - mockFs(); + mockConfig(); config.reload(); const yaml = config.asYaml(); assert.strictEqual(yaml, `limits: @@ -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"); @@ -136,16 +143,13 @@ 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)); @@ -153,4 +157,4 @@ comparators: assert.strictEqual(cfg.comparators.custom[0].path, "build/file"); assert.strictEqual(cfg.comparators.custom[1].path, "build/file2"); }); -}); \ No newline at end of file +});