diff --git a/package-lock.json b/package-lock.json index 881d042..cc98f46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "bath-es5": "^3.0.3", - "dereference-json-schema": "^0.2.1", + "dereference-json-schema": "^0.2.3", "openapi-types": "^12.1.3" }, "devDependencies": { @@ -2228,9 +2228,10 @@ } }, "node_modules/dereference-json-schema": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/dereference-json-schema/-/dereference-json-schema-0.2.1.tgz", - "integrity": "sha512-uzJsrg225owJyRQ8FNTPHIuBOdSzIZlHhss9u6W8mp7jJldHqGuLv9cULagP/E26QVJDnjtG8U7Dw139mM1ydA==" + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/dereference-json-schema/-/dereference-json-schema-0.2.3.tgz", + "integrity": "sha512-CBVoEuf2tKhqnUhoKjvX4wo5NVxDSHxInqwExQfUNEK67aX+LPC27Vg+6CApi+KRebABJZAWhHBVoNpKfhMssg==", + "license": "MIT" }, "node_modules/detect-newline": { "version": "3.1.0", diff --git a/package.json b/package.json index 58c3818..bc82f5c 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "dependencies": { "bath-es5": "^3.0.3", - "dereference-json-schema": "^0.2.1", + "dereference-json-schema": "^0.2.3", "openapi-types": "^12.1.3" }, "devDependencies": { @@ -67,7 +67,7 @@ "build": "tsc", "watch-build": "tsc -w", "prepare": "npm run build", - "test": "NODE_ENV=test jest", + "test": "NODE_ENV=test NODE_OPTIONS=--expose-gc jest", "lint": "prettier --check src/**/*.ts __tests__/**/*.ts", "lint:fix": "prettier --write src/**/*.ts __tests__/**/*.ts" }, diff --git a/src/client.test.ts b/src/client.test.ts index 20c27af..29b3f75 100644 --- a/src/client.test.ts +++ b/src/client.test.ts @@ -246,6 +246,23 @@ describe('OpenAPIClientAxios', () => { const api = new OpenAPIClientAxios({ definition: '/example-pet-api.openapi.json' }); expect(api.initSync).toThrowError(); }); + + test('does not retain the definition of a discarded client', async () => { + const gc = (global as { gc?: () => void }).gc; + expect(gc).toBeDefined(); + + const createDiscardedClient = () => { + const fresh = JSON.parse(JSON.stringify(definition)); + new OpenAPIClientAxios({ definition: fresh }).initSync(); + return new WeakRef(fresh); + }; + const ref = createDiscardedClient(); + + await new Promise((resolve) => setImmediate(resolve)); + gc!(); + + expect(ref.deref()).toBeUndefined(); + }); }); describe('client', () => {