UNPKG

testeranto

Version:

the AI powered BDD test framework for typescript projects

411 lines (408 loc) 11.5 kB
import { createRequire } from 'module';const require = createRequire(import.meta.url); import { Pure_default } from "../chunk-62UVCSQC.mjs"; // src/lib/pmProxy.test/mockPMBase.ts var MockPMBase = class { constructor(configs) { this.calls = {}; this.testResourceConfiguration = {}; this.configs = configs || {}; } // Common tracking functionality trackCall(method, args) { if (!this.calls[method]) { this.calls[method] = []; } this.calls[method].push(args); } getCallCount(method) { return this.calls[method]?.length || 0; } getLastCall(method) { const calls = this.calls[method]; return calls ? calls[calls.length - 1] : null; } // Add missing methods used in tests // writeFileSync(path: string, content: string): Promise<boolean> { // this.trackCall('writeFileSync', { path, content }); // return Promise.resolve(true); // } // end(uid: number): Promise<boolean> { // this.trackCall('end', { uid }); // return Promise.resolve(true); // } // Minimal implementations of required methods launchSideCar(n, testName, projectName) { this.trackCall("launchSideCar", { n, testName, projectName }); return Promise.resolve(); } end(uid) { this.trackCall("end", { uid }); console.debug(`Ending test with uid ${uid}`); return Promise.resolve(true); } // Add debug method debug(message) { console.debug(`[MockPMBase] ${message}`); this.trackCall("debug", { message }); } writeFileSync(path, content, testName) { this.trackCall("writeFileSync", { path, content, testName }); return Promise.resolve(true); } createWriteStream(path, testName) { this.trackCall("createWriteStream", { path, testName }); return Promise.resolve(0); } screencast(opts, testName, page) { this.trackCall("screencast", { opts, testName, page }); return Promise.resolve({}); } customScreenShot(opts, testName, pageUid) { this.trackCall("customScreenShot", { opts, testName, pageUid }); return Promise.resolve({}); } testArtiFactoryfileWriter(tLog, callback) { return (fPath, value) => { this.trackCall("testArtiFactoryfileWriter", { fPath, value }); callback(Promise.resolve()); }; } // Other required PM_Base methods with minimal implementations closePage(p) { return Promise.resolve(); } $(selector, p) { return Promise.resolve(); } click(selector, page) { return Promise.resolve(); } goto(p, url) { return Promise.resolve(); } newPage() { return Promise.resolve("mock-page"); } pages() { return Promise.resolve(["mock-page"]); } waitForSelector(p, s) { return Promise.resolve(true); } focusOn(selector, p) { return Promise.resolve(); } typeInto(value, p) { return Promise.resolve(); } getAttribute(selector, attribute, p) { return Promise.resolve(); } getInnerHtml(selector, p) { return Promise.resolve(); } isDisabled(selector, p) { return Promise.resolve(false); } screencastStop(s) { return Promise.resolve(); } existsSync(destFolder) { return false; } mkdirSync(fp) { return Promise.resolve(); } write(uid, contents) { return Promise.resolve(true); } page(p) { return "mock-page"; } doInPage(p, cb) { return Promise.resolve(); } customclose() { return Promise.resolve(); } }; // src/Pure.test.ts var implementation = { suites: { Default: "PureTesteranto Test Suite" }, givens: { Default: () => { const pm = new MockPMBase(); return { pm, config: {}, proxies: { butThenProxy: (pm2, path) => ({ ...pm2, writeFileSync: (p, c) => { return pm2.writeFileSync(`${path}/butThen/${p}`, c); } }), andWhenProxy: (pm2, path) => ({ ...pm2, writeFileSync: (p, c) => { return pm2.writeFileSync(`${path}/andWhen/${p}`, c); } }), beforeEachProxy: (pm2, suite) => ({ ...pm2, writeFileSync: (p, c) => { return pm2.writeFileSync(`suite-${suite}/beforeEach/${p}`, c); } }) } }; } }, whens: { applyProxy: (proxyType) => async (store, tr, utils) => { switch (proxyType) { case "invalidConfig": throw new Error("Invalid configuration"); case "missingProxy": return { ...store, pm: {} }; case "largePayload": return { ...store, largePayload: true, pm: { ...store.pm, writeFileSync: async (p, c) => { if (c.length > 1e6) { return true; } throw new Error("Payload too small"); } } }; case "resourceConfig": return { ...store, pm: { ...store.pm, testResourceConfiguration: { name: "test-resource" } } }; default: return store; } }, addArtifact: (artifact) => async (store) => { return { ...store, artifacts: [...store.artifacts || [], artifact] }; }, setTestJobs: (jobs) => async (store) => { return { ...store, testJobs: jobs }; }, modifySpecs: (modifier) => async (store) => { return { ...store, specs: modifier(store.specs || []) }; } }, thens: { initializedProperly: () => async (store, tr, utils) => { if (!store.pm) { throw new Error("PM not initialized"); } return store; }, specsGenerated: () => async (store, tr, utils) => { return store; }, jobsCreated: () => async (store, tr, utils) => { return store; }, artifactsTracked: () => async (store, tr, utils) => { return store; }, testRunSuccessful: () => async (store, tr, utils) => { return store; }, specsModified: (expectedCount) => async (store, tr, utils) => { return store; }, verifyProxy: (expectedPath) => async (store, tr, utils) => { return store; }, verifyNoProxy: () => async (store, tr, utils) => { return store; }, verifyError: (expectedError) => async (store, tr, utils) => { return store; }, verifyResourceConfig: () => async (store, tr, utils) => { return store; }, verifyLargePayload: () => async (store, tr, utils) => { return store; }, verifyTypeSafety: () => async (store, tr, utils) => { return store; } } }; var specification = (Suite, Given, When, Then) => [ Suite.Default("Core Functionality", { initializationTest: Given.Default( ["Should initialize with default configuration"], [], [Then.verifyNoProxy()] ), resourceConfigTest: Given.Default( ["Should handle test resource configuration"], [When.applyProxy("resourceConfig")], [Then.verifyResourceConfig()] ) }), Suite.Default("Proxy Integration", { butThenProxyTest: Given.Default( ["Should integrate with butThenProxy"], [When.applyProxy("butThenProxy")], [Then.verifyProxy("test/path/butThen/expected")] ), andWhenProxyTest: Given.Default( ["Should integrate with andWhenProxy"], [When.applyProxy("andWhenProxy")], [Then.verifyProxy("test/path/andWhen/expected")] ), beforeEachProxyTest: Given.Default( ["Should integrate with beforeEachProxy"], [When.applyProxy("beforeEachProxy")], [Then.verifyProxy("suite-1/beforeEach/expected")] ) }), Suite.Default("Error Handling", { invalidConfigTest: Given.Default( ["Should handle invalid configuration"], [When.applyProxy("invalidConfig")], [Then.verifyError("Invalid configuration")] ), missingProxyTest: Given.Default( ["Should handle missing proxy"], [When.applyProxy("missingProxy")], [Then.verifyError("Proxy not found")] ) }), Suite.Default("Performance", { multipleProxiesTest: Given.Default( ["Should handle multiple proxies efficiently"], [ When.applyProxy("butThenProxy"), When.applyProxy("andWhenProxy"), When.applyProxy("beforeEachProxy") ], [ Then.verifyProxy("test/path/butThen/expected"), Then.verifyProxy("test/path/andWhen/expected"), Then.verifyProxy("suite-1/beforeEach/expected") ] ), largePayloadTest: Given.Default( ["Should handle large payloads"], [When.applyProxy("largePayload")], [Then.verifyLargePayload()] ) }), Suite.Default("Cross-Component Verification", { proxyChainTest: Given.Default( ["Proxies should chain correctly"], [When.applyProxy("butThenProxy"), When.applyProxy("andWhenProxy")], [Then.verifyProxy("test/path/andWhen/butThen/expected")] ), errorPropagationTest: Given.Default( ["Errors should propagate across components"], [When.applyProxy("invalidConfig")], [Then.verifyError("Invalid configuration")] ), resourceSharingTest: Given.Default( ["Resources should be shared correctly"], [When.applyProxy("resourceConfig")], [Then.verifyResourceConfig()] ) }), Suite.Default("Type Safety", { strictTypeTest: Given.Default( ["Should enforce type safety"], [When.applyProxy("typeSafe")], [Then.verifyTypeSafety()] ), invalidTypeTest: Given.Default( ["Should reject invalid types"], [When.applyProxy("invalidType")], [Then.verifyError("Type mismatch")] ) }), Suite.Default("Integration Tests", { // Verify builders work together builderIntegration: Given.Default( ["BaseBuilder and ClassBuilder should integrate properly"], [], [ Then.initializedProperly(), Then.specsGenerated(), Then.jobsCreated(), Then.artifactsTracked() ] ), // Verify PM proxy integration pmProxyIntegration: Given.Default( ["PM proxies should work with test runners"], [When.applyProxy("butThenProxy")], [Then.verifyProxy("test/path/butThen/expected")] ), // Verify full test lifecycle fullLifecycle: Given.Default( ["Should complete full test lifecycle"], [ When.addArtifact(Promise.resolve("test")), When.setTestJobs([]), When.modifySpecs((specs) => [...specs]) ], [Then.testRunSuccessful(), Then.artifactsTracked(), Then.specsModified(0)] ) }) ]; var testAdapter = { beforeEach: async (subject, initializer, testResource, initialValues, pm) => { const initialized = initializer(); return { pm: initialized.pm }; }, andWhen: async (store, whenCB, testResource, pm) => { const result = await whenCB(store, testResource, pm); return result; }, butThen: async (store, thenCB, testResource, pm) => { const result = await thenCB(store, testResource, pm); return result; }, afterEach: async (store, key, pm) => store, afterAll: async (store, pm) => { }, beforeAll: async (input, testResource, pm) => ({}), assertThis: (x) => x }; var Pure_test_default = Pure_default( null, // No initial input specification, implementation, testAdapter ); export { Pure_test_default as default };