Skip to content

Commit 460a2ab

Browse files
authored
Improve missing cassette errors (DataDog#280)
1 parent b06f98a commit 460a2ab

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

features/support/vcr.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { After, Before } from "@cucumber/cucumber";
99
import { World } from "./world";
1010
import { ITestCaseHookParameter } from "@cucumber/cucumber/lib/support_code_library_builder/types";
1111
import { MODES } from "@pollyjs/utils";
12+
import { FetchError } from "node-fetch";
1213

1314
Polly.register(NodeHttpAdapter);
1415
Polly.register(FSPersister);
@@ -70,9 +71,18 @@ Before(function (
7071
) {
7172
fs.mkdirSync(path.dirname(frozen), { recursive: true });
7273
fs.writeFileSync(frozen, JSON.stringify(date));
74+
} else if (this.polly?.mode == MODES.REPLAY) {
75+
throw new Error(`Time file '${frozen}' not found: create one setting \`RECORD=true\` or ignore it using \`RECORD=none\``);
7376
}
7477
}
7578

79+
const cassette = path.join(recordingsDir, this.polly?.recordingId, "recording.har")
80+
const cassetteExists = fs.existsSync(cassette)
81+
82+
if (!cassetteExists && this.polly?.mode == MODES.REPLAY) {
83+
throw new Error(`Cassette '${cassette}' not found: create one setting \`RECORD=true\` or ignore it using \`RECORD=none\``);
84+
}
85+
7686
const now = date.getTime() / 1000;
7787
const name = pickle.name?.replace(/[^A-Za-z0-9]+/g, "_").substr(0, 100);
7888
const prefix =

0 commit comments

Comments
 (0)