Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix latest compile TS and Node 20 workflow failures #7512

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
build:
runs-on: ubuntu-latest
strategy:
# Prevent GitHub from canceling all in-progress jobs when a matrix job fails
fail-fast: false
matrix:
node: ['18', '20']

Expand Down
2 changes: 1 addition & 1 deletion packages/rxjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"scripts": {
"lint": "eslint --ext=ts,js src spec spec-dtslint",
"dtslint": "npm run lint && tsc -b ./src/tsconfig.types.json",
"test": "cross-env TS_NODE_PROJECT=tsconfig.mocha.json mocha --config spec/support/.mocharc.js \"spec/**/*-spec.ts\"",
"test": "cross-env TS_NODE_PROJECT=tsconfig.mocha.json node --expose-gc ../../node_modules/.bin/_mocha --config spec/support/.mocharc.js \"spec/**/*-spec.ts\"",
"test:esm": "node spec/module-test-spec.mjs",
"test:circular": "dependency-cruiser --validate .dependency-cruiser.json -x \"^node_modules\" dist/esm",
"test:import": "node integration/import/runner.js",
Expand Down
57 changes: 31 additions & 26 deletions packages/rxjs/spec/Subscriber-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import type { Observer} from 'rxjs';
import type { Observer } from 'rxjs';
import { Subscriber, Observable, of, config, operate } from 'rxjs';
import * as sinon from 'sinon';
import { asInteropSubscriber } from './helpers/interop-helper';
Expand Down Expand Up @@ -301,35 +301,40 @@ describe('Subscriber', () => {
});
});

const FinalizationRegistry = (global as any).FinalizationRegistry;
if (FinalizationRegistry && global.gc) {
it('should not leak the destination', (done) => {
let observer: Observer<number> | undefined = {
next() {
/* noop */
},
error() {
/* noop */
},
complete() {
/* noop */
},
};
it('should not leak the destination', function (done) {
this.timeout(10000);

const registry = new FinalizationRegistry((value: any) => {
expect(value).to.equal('observer');
done();
});
registry.register(observer, 'observer');
const observer: Observer<number> | undefined = {
next() {
/* noop */
},
error() {
/* noop */
},
complete() {
/* noop */
},
};

/**
* Use WeakRef instead of FinalizationRegistry (as was originally used). Per MDN, FinalizationRegistry is not a deterministic enough mechanism
* on which to base reliable tests: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
*/
const weakRef = new WeakRef(observer);

const subscription = of(42).subscribe(observer);
// Subscribe to the observable which will complete and unsubscribe automatically. This should not cause any remaining references to the observer after garbage collection.
of(42).subscribe(observer);

observer = undefined;
setTimeout(() => {
global.gc?.();
});
} else {
console.warn(`No support for FinalizationRegistry in Node ${process.version}`);
}

if (weakRef.deref() === undefined) {
done();
} else {
done(new Error('Observer was not garbage collected - possible memory leak'));
}
}, 1000);
});
});

describe('operate', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rxjs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"moduleResolution": "node",
"stripInternal": true,
"noEmit": true,
"lib": ["esnext", "dom"],
"lib": ["es2022", "dom"],
"target": "esnext",
"baseUrl": ".",
"paths": {
Expand Down
Loading