Skip to content

Commit f9d8e3f

Browse files
authored
fix npx can not find playwright module (#13)
* change test location
1 parent ec2f6e0 commit f9d8e3f

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ npm i @octomind/debugtopus
1212
You should get the base command including id and token from octomind. You should just add the url of the app you would like to run the test against:
1313

1414
```shell
15-
npx debugtopus --id <test-case-id> --token <token> --url <local-url>
15+
npx @octomind/debugtopus --id <test-case-id> --token <token> --url <local-url>
1616
```

src/debugtopus.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Command } from "commander";
2-
import { dirSync } from "tmp";
3-
import { writeFileSync } from "fs";
2+
import { writeFileSync, mkdirSync, existsSync } from "fs";
43
import { promisify } from "util";
54
import { exec } from "child_process";
65
import { randomUUID } from "crypto";
@@ -43,15 +42,19 @@ export const prepareTestRun = async ({
4342
}> => {
4443
const code = await getPlaywrightCode(testId, token, url, octomindUrl);
4544

46-
const tempDir = dirSync();
47-
const testFilePath = path.join(tempDir.name, `${randomUUID()}.spec.ts`);
45+
const dirname = __dirname;
46+
const tempDir = path.join(dirname, "..", "temp");
47+
const outputDir = "output";
48+
if (!existsSync(tempDir)) {
49+
mkdirSync(tempDir);
50+
}
51+
const testFilePath = path.join(tempDir, `${randomUUID()}.spec.ts`);
4852
writeFileSync(testFilePath, code);
4953

50-
const configFilePath = path.join(tempDir.name, `${randomUUID()}.config.ts`);
51-
const outputDir = dirSync();
52-
writeFileSync(configFilePath, getConfig(url, outputDir.name));
54+
const configFilePath = path.join(tempDir, `${randomUUID()}.config.ts`);
55+
writeFileSync(configFilePath, getConfig(url, outputDir));
5356

54-
return { testFilePath, configFilePath, outputDir: outputDir.name };
57+
return { testFilePath, configFilePath, outputDir };
5558
};
5659

5760
export const debugtopus = async (): Promise<void> => {

tests/debugtopus.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
import axios from "axios";
22
import { getConfig, prepareTestRun } from "../src/debugtopus";
33
import { readFileSync } from "fs";
4+
import fs from "fs/promises";
45

56
jest.mock("axios");
67

78
describe("prepareTestRun", () => {
8-
const testCode = "this is the test code";
9+
const testCode = "";
910
const url = "https://foo.bar";
1011
const testId = "testId";
1112
const token = "token";
13+
const octomindUrl = "https://app.octomind.dev";
1214
beforeEach(() => {
1315
(axios.get as jest.Mock).mockResolvedValue({
1416
data: { testCode },
1517
});
1618
});
1719

20+
afterEach(async () => {
21+
await fs.rm("temp", { recursive: true });
22+
});
23+
1824
it("generates the correct files", async () => {
1925
const { testFilePath, configFilePath, outputDir } = await prepareTestRun({
26+
octomindUrl,
2027
token,
2128
testId,
2229
url,

0 commit comments

Comments
 (0)