|
| 1 | +// Load .env file if it exists (quiet - no error if missing) |
| 2 | +try { |
| 3 | + process.loadEnvFile(); |
| 4 | +} |
| 5 | +catch { |
| 6 | + // .env file not found or not readable - ignore silently |
| 7 | +} |
| 8 | + |
| 9 | +// Import Node.js Dependencies |
| 10 | +import assert from "node:assert"; |
| 11 | +import path from "node:path"; |
| 12 | +import { describe, test } from "node:test"; |
| 13 | +import { fileURLToPath } from "node:url"; |
| 14 | + |
| 15 | +// Import Internal Dependencies |
| 16 | +import { runProcess } from "../helpers/cliCommandRunner.js"; |
| 17 | +import { arrayFromAsync } from "../helpers/utils.js"; |
| 18 | + |
| 19 | +// CONSTANTS |
| 20 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 21 | +const kProcessDir = path.join(__dirname, "..", "process"); |
| 22 | + |
| 23 | +describe("CLI Commands: extract integrity", () => { |
| 24 | + test("should not find an integrity diff", async() => { |
| 25 | + const expectedLine = "no integrity diff found"; |
| 26 | + |
| 27 | + const lines = await arrayFromAsync(runProcess({ path: path.join(kProcessDir, "extract-integrity/valid-spec.js") })); |
| 28 | + |
| 29 | + assert.equal(lines[0], expectedLine, `should be ${expectedLine}`); |
| 30 | + }); |
| 31 | + |
| 32 | + test("should not check integrity if version is missing", async() => { |
| 33 | + const expectedLine = " [!] You must specify a version for 'express' package."; |
| 34 | + |
| 35 | + const lines = await arrayFromAsync(runProcess({ path: path.join(kProcessDir, "extract-integrity/missing-version.js") })); |
| 36 | + |
| 37 | + assert.equal(lines[0], expectedLine, `should be ${expectedLine}`); |
| 38 | + }); |
| 39 | + |
| 40 | + test("should not check integrity for invalid spec", async() => { |
| 41 | + const expectedLine = " [!] The package spec '' is invalid."; |
| 42 | + |
| 43 | + const lines = await arrayFromAsync(runProcess({ path: path.join(kProcessDir, "extract-integrity/invalid-spec.js") })); |
| 44 | + |
| 45 | + assert.equal(lines[0], expectedLine, `should be ${expectedLine}`); |
| 46 | + }); |
| 47 | + |
| 48 | + test("should not check integrity if spec is not found", async() => { |
| 49 | + const expectedLine = " [!] The package spec 'express@not-found' could not be found from the npm registry."; |
| 50 | + |
| 51 | + const lines = await arrayFromAsync(runProcess({ path: path.join(kProcessDir, "extract-integrity/not-found.js") })); |
| 52 | + |
| 53 | + assert.equal(lines[0], expectedLine, `should be ${expectedLine}`); |
| 54 | + }); |
| 55 | +}); |
0 commit comments