mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Implement e2e tests
This commit is contained in:
parent
f817bf887a
commit
059cba06bc
17 changed files with 163 additions and 293 deletions
|
|
@ -2,22 +2,14 @@ import { test } from "node:test";
|
|||
import assert from "node:assert";
|
||||
import { commandArgumentScanner, checkChangesFromArgs } from "./commandArgumentScanner.js";
|
||||
|
||||
test("commandArgumentScanner", async (t) => {
|
||||
await t.test("should create scanner with default options", () => {
|
||||
test("commandArgumentScanner factory", async (t) => {
|
||||
await t.test("should create scanner with required interface", () => {
|
||||
const scanner = commandArgumentScanner();
|
||||
|
||||
assert.ok(scanner);
|
||||
assert.strictEqual(typeof scanner.shouldScan, "function");
|
||||
assert.strictEqual(typeof scanner.scan, "function");
|
||||
});
|
||||
|
||||
await t.test("should create scanner with ignoreDryRun option", () => {
|
||||
const scanner = commandArgumentScanner({ ignoreDryRun: true });
|
||||
|
||||
assert.ok(scanner);
|
||||
assert.strictEqual(typeof scanner.shouldScan, "function");
|
||||
assert.strictEqual(typeof scanner.scan, "function");
|
||||
});
|
||||
});
|
||||
|
||||
test("shouldScan", async (t) => {
|
||||
|
|
@ -41,20 +33,6 @@ test("shouldScan", async (t) => {
|
|||
const result = scanner.shouldScan(["install", "--dry-run", "requests"]);
|
||||
assert.strictEqual(result, true);
|
||||
});
|
||||
|
||||
await t.test("should return true for download command", () => {
|
||||
const scanner = commandArgumentScanner();
|
||||
|
||||
const result = scanner.shouldScan(["download", "flask"]);
|
||||
assert.strictEqual(result, true);
|
||||
});
|
||||
|
||||
await t.test("should return true for wheel command", () => {
|
||||
const scanner = commandArgumentScanner();
|
||||
|
||||
const result = scanner.shouldScan(["wheel", "django"]);
|
||||
assert.strictEqual(result, true);
|
||||
});
|
||||
});
|
||||
|
||||
test("scan", async (t) => {
|
||||
|
|
@ -129,46 +107,6 @@ test("scan", async (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
await t.test("should work with download command", () => {
|
||||
const scanner = commandArgumentScanner();
|
||||
|
||||
const result = scanner.scan(["download", "django==4.2.0"]);
|
||||
assert.strictEqual(result.length, 1);
|
||||
assert.deepEqual(result[0], {
|
||||
name: "django",
|
||||
version: "4.2.0",
|
||||
type: "add",
|
||||
});
|
||||
});
|
||||
|
||||
await t.test("should work with wheel command", () => {
|
||||
const scanner = commandArgumentScanner();
|
||||
|
||||
const result = scanner.scan(["wheel", "numpy==1.24.0"]);
|
||||
assert.strictEqual(result.length, 1);
|
||||
assert.deepEqual(result[0], {
|
||||
name: "numpy",
|
||||
version: "1.24.0",
|
||||
type: "add",
|
||||
});
|
||||
});
|
||||
|
||||
await t.test("should parse packages even for unsupported commands", () => {
|
||||
const scanner = commandArgumentScanner();
|
||||
|
||||
// Note: The parser treats the first non-flag arg as the command and skips it
|
||||
// So "uninstall" is treated as the command, and "requests" is parsed as a package
|
||||
// The scanner itself doesn't filter by command type - that's done at a higher level
|
||||
const result = scanner.scan(["uninstall", "requests"]);
|
||||
assert.ok(Array.isArray(result));
|
||||
assert.strictEqual(result.length, 1);
|
||||
assert.deepEqual(result[0], {
|
||||
name: "requests",
|
||||
version: "latest",
|
||||
type: "add",
|
||||
});
|
||||
});
|
||||
|
||||
await t.test("should handle === exact version specifier", () => {
|
||||
const scanner = commandArgumentScanner();
|
||||
|
||||
|
|
@ -182,8 +120,8 @@ test("scan", async (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("checkChangesFromArgs", async (t) => {
|
||||
await t.test("should extract changes from install args", () => {
|
||||
test("checkChangesFromArgs helper", async (t) => {
|
||||
await t.test("should extract packages from args", () => {
|
||||
const result = checkChangesFromArgs(["install", "requests==2.28.0", "flask"]);
|
||||
|
||||
assert.strictEqual(result.length, 2);
|
||||
|
|
@ -199,17 +137,8 @@ test("checkChangesFromArgs", async (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
await t.test("should return empty array for commands with no packages", () => {
|
||||
const result = checkChangesFromArgs(["install", "-r", "requirements.txt"]);
|
||||
|
||||
assert.ok(Array.isArray(result));
|
||||
assert.strictEqual(result.length, 0);
|
||||
});
|
||||
|
||||
await t.test("should handle empty args", () => {
|
||||
const result = checkChangesFromArgs([]);
|
||||
|
||||
assert.ok(Array.isArray(result));
|
||||
assert.strictEqual(result.length, 0);
|
||||
assert.deepStrictEqual(result, []);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue