w7a9q
w7a9q2mo ago

Deno runs the whole script instead of the method

I have following test:
import { expect } from "jsr:@std/expect";
import { validateInput } from "./webp.ts";

Deno.test("invalid input", () => {
const fn = validateInput;
const result = fn('/root', 55);
expect(result).toThrow();
});
import { expect } from "jsr:@std/expect";
import { validateInput } from "./webp.ts";

Deno.test("invalid input", () => {
const fn = validateInput;
const result = fn('/root', 55);
expect(result).toThrow();
});
When I run deno test it runs the whole webp.ts script instead of just the validateInput() method.
3 Replies
bartlomieju
bartlomieju2mo ago
Can you give more info? What is the content of the webp.ts that is not expected to run?
w7a9q
w7a9qOP2mo ago
It starts with:
import { exec } from "node:child_process";
import process from "node:process";

const directoryArg: string = process.argv[2];
const qualityArg: string = process.argv[3];
import { exec } from "node:child_process";
import process from "node:process";

const directoryArg: string = process.argv[2];
const qualityArg: string = process.argv[3];
I expected to run only the validateInput method.
bartlomieju
bartlomieju2mo ago
That's not how ES modules work. All file is evaluated when it is imported