From f14f3b82687411317aaacdfba853ba7ffd4fb266 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Sat, 28 Sep 2024 12:02:18 +0100 Subject: [PATCH] add convenience includesContent audits --- test-packages/support/audit-assertions.ts | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test-packages/support/audit-assertions.ts b/test-packages/support/audit-assertions.ts index 9e52d4a287..dbad64b71e 100644 --- a/test-packages/support/audit-assertions.ts +++ b/test-packages/support/audit-assertions.ts @@ -180,6 +180,42 @@ export class ExpectModule { }); } + doesNotIncludeContent(src: string, message?: string) { + if (!this.module) { + this.emitMissingModule(); + return; + } + if (this.module.type === 'unparseable') { + this.emitUnparsableModule(message); + return; + } + + this.expectAudit.assert.pushResult({ + result: !this.module.content.includes(src), + actual: this.module.content, + expected: true, + message: message ?? `Expected ${this.inputName} to not contain ${src}`, + }); + } + + includesContent(src: string, message?: string) { + if (!this.module) { + this.emitMissingModule(); + return; + } + if (this.module.type === 'unparseable') { + this.emitUnparsableModule(message); + return; + } + + this.expectAudit.assert.pushResult({ + result: this.module.content.includes(src), + actual: this.module.content, + expected: true, + message: message ?? `Expected ${this.inputName} to contain ${src}`, + }); + } + private emitUnparsableModule(message?: string) { this.expectAudit.assert.pushResult({ result: false, @@ -327,6 +363,8 @@ class EmptyExpectModule implements PublicAPI { codeEquals() {} codeContains() {} withContents() {} + doesNotIncludeContent() {} + includesContent() {} resolves(): PublicAPI { return new EmptyExpectResolution() as PublicAPI;