Skip to content

Commit

Permalink
[rc3] Make ./internal/test exports conditional (microsoft#20828)
Browse files Browse the repository at this point in the history
## Description

Adjusts the /internal/test exports of merge-tree and id-compressor to be
conditional.

Cherry-pick of microsoft#20729 into rc3.

This also includes fixes to two follow-up issues this commit introduced,
i.e. cherry-picks microsoft#20808, and microsoft#20827.

---------

Co-authored-by: Abram Sanderson <absander@microsoft.com>
Co-authored-by: Alex Villarreal <716334+alexvy86@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 26, 2024
1 parent 9fc4a71 commit ee2267c
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 21 deletions.
2 changes: 1 addition & 1 deletion common/build/build-common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ files](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0
- tsconfig.node16.json - This config extends base and sets `module: Node16` and `moduleResolution: Node16`. It is intended for all
builds.
- tsconfig.test.node16.json - This config disables some settings that we don't want to use in test code, like `declaration` and
`decarationMap`. It also enables the `node` types by default.
`decarationMap`. It also enables the `node` types by default, and turns on the "allow-ff-test-exports" [condition](https://nodejs.org/api/packages.html#conditional-exports), which allows imports for test-only indexes used in a few packages.

### Dual Build Pattern

Expand Down
1 change: 1 addition & 0 deletions common/build/build-common/tsconfig.test.node16.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": ["./tsconfig.base.json", "./tsconfig.node16.json"],
"compilerOptions": {
"composite": false,
"customConditions": ["allow-ff-test-exports"],
"types": ["node"],
"declaration": false,
"declarationMap": false,
Expand Down
16 changes: 9 additions & 7 deletions packages/dds/merge-tree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
}
},
"./internal/test": {
"import": {
"types": "./lib/test/index.d.ts",
"default": "./lib/test/index.js"
},
"require": {
"types": "./dist/test/index.d.ts",
"default": "./dist/test/index.js"
"allow-ff-test-exports": {
"import": {
"types": "./lib/test/index.d.ts",
"default": "./lib/test/index.js"
},
"require": {
"types": "./dist/test/index.d.ts",
"default": "./dist/test/index.js"
}
}
}
},
Expand Down
29 changes: 29 additions & 0 deletions packages/dds/sequence/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,33 @@ module.exports = {
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
},
settings: {
"import/extensions": [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
},
"import/resolver": {
typescript: {
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
conditionNames: [
"allow-ff-test-exports",

// Default condition names below, see https://www.npmjs.com/package/eslint-import-resolver-typescript#conditionnames
"types",
"import",

// APF: https://angular.io/guide/angular-package-format
"esm2020",
"es2020",
"es2015",

"require",
"node",
"node-addons",
"browser",
"default",
],
},
},
},
};
10 changes: 9 additions & 1 deletion packages/dds/sequence/src/sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import {
IJSONSegment,
IMergeTreeAnnotateMsg,
IMergeTreeDeltaOp,
// eslint-disable-next-line import/no-deprecated
IMergeTreeGroupMsg,
// eslint-disable-next-line import/no-deprecated
IMergeTreeObliterateMsg,
IMergeTreeOp,
IMergeTreeRemoveMsg,
Expand All @@ -30,9 +32,11 @@ import {
PropertySet,
ReferencePosition,
ReferenceType,
// eslint-disable-next-line import/no-deprecated
SegmentGroup,
SlidingPreference,
createAnnotateRangeOp, // eslint-disable-next-line import/no-deprecated
createAnnotateRangeOp,
// eslint-disable-next-line import/no-deprecated
createGroupOp,
createInsertOp,
createObliterateRangeOp,
Expand Down Expand Up @@ -180,6 +184,7 @@ export abstract class SharedSegmentSequence<T extends ISegment>
}

case MergeTreeDeltaType.OBLITERATE: {
// eslint-disable-next-line import/no-deprecated
const lastRem = ops[ops.length - 1] as IMergeTreeObliterateMsg;
if (lastRem?.pos1 === r.position) {
assert(
Expand Down Expand Up @@ -243,6 +248,7 @@ export abstract class SharedSegmentSequence<T extends ISegment>
/** `Deferred` that triggers once the object is loaded */
protected loadedDeferred = new Deferred<void>();
// cache out going ops created when partial loading
// eslint-disable-next-line import/no-deprecated
private readonly loadedDeferredOutgoingOps: [IMergeTreeOp, SegmentGroup | SegmentGroup[]][] =
[];
// cache incoming ops that arrive when partial loading
Expand Down Expand Up @@ -340,6 +346,7 @@ export abstract class SharedSegmentSequence<T extends ISegment>
* release, as group ops are redundant with the native batching capabilities
* of the runtime
*/
// eslint-disable-next-line import/no-deprecated
public groupOperation(groupOp: IMergeTreeGroupMsg) {
this.guardReentrancy(() => this.client.localTransaction(groupOp));
}
Expand Down Expand Up @@ -654,6 +661,7 @@ export abstract class SharedSegmentSequence<T extends ISegment>
this.submitSequenceMessage(
this.client.regeneratePendingOp(
content as IMergeTreeOp,
// eslint-disable-next-line import/no-deprecated
localOpMetadata as SegmentGroup | SegmentGroup[],
),
);
Expand Down
2 changes: 2 additions & 0 deletions packages/dds/sequence/src/sharedString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { IChannelAttributes, IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
import {
// eslint-disable-next-line import/no-deprecated
IMergeTreeTextHelper,
IRelativePosition,
ISegment,
Expand Down Expand Up @@ -87,6 +88,7 @@ export class SharedString
return this;
}

// eslint-disable-next-line import/no-deprecated
private readonly mergeTreeTextHelper: IMergeTreeTextHelper;

constructor(
Expand Down
1 change: 0 additions & 1 deletion packages/dds/sequence/src/test/generateSharedStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License.
*/

// eslint-disable-next-line import/no-internal-modules
import { SnapshotLegacy as Snapshot } from "@fluidframework/merge-tree/internal/test";
import * as mocks from "@fluidframework/test-runtime-utils/internal";
import { MersenneTwister19937, Random } from "random-js";
Expand Down
1 change: 0 additions & 1 deletion packages/dds/sequence/src/test/intervalRebasing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { strict as assert } from "assert";

import { IChannelServices } from "@fluidframework/datastore-definitions";
// eslint-disable-next-line import/no-internal-modules
import { useStrictPartialLengthChecks } from "@fluidframework/merge-tree/internal/test";
import {
MockContainerRuntimeFactoryForReconnection,
Expand Down
1 change: 0 additions & 1 deletion packages/dds/sequence/src/test/sequenceDeltaEvent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
createInsertSegmentOp,
createRemoveRangeOp,
} from "@fluidframework/merge-tree/internal";
// eslint-disable-next-line import/no-internal-modules
import { TestClient } from "@fluidframework/merge-tree/internal/test";

import { SequenceDeltaEvent } from "../sequenceDeltaEvent.js";
Expand Down
1 change: 0 additions & 1 deletion packages/dds/sequence/src/test/subSequence.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
createInsertSegmentOp,
createRemoveRangeOp,
} from "@fluidframework/merge-tree/internal";
// eslint-disable-next-line import/no-internal-modules
import { TestClient } from "@fluidframework/merge-tree/internal/test";

import { SubSequence } from "../sharedSequence.js";
Expand Down
29 changes: 29 additions & 0 deletions packages/dds/tree/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,33 @@ module.exports = {
},
},
],
settings: {
"import/extensions": [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
},
"import/resolver": {
typescript: {
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
conditionNames: [
"allow-ff-test-exports",

// Default condition names below, see https://www.npmjs.com/package/eslint-import-resolver-typescript#conditionnames
"types",
"import",

// APF: https://angular.io/guide/angular-package-format
"esm2020",
"es2020",
"es2015",

"require",
"node",
"node-addons",
"browser",
"default",
],
},
},
},
};
3 changes: 3 additions & 0 deletions packages/dds/tree/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
],
"mochaExplorer.configFile": ".mocharc.cjs",
"mochaExplorer.timeout": 999999,
// This extension appears to invoke mocha programmatically, meaning that the enablement of this option in the common
// mocha test config isn't sufficient; it also needs to be enabled here.
"mochaExplorer.nodeArgv": ["--conditions", "allow-ff-test-exports"],
"cSpell.words": ["deprioritized", "endregion", "insertable", "reentrantly", "unhydrated"],
}
1 change: 1 addition & 0 deletions packages/dds/tree/src/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"module": "Node16",
"moduleResolution": "Node16",
"types": ["node", "mocha"],
"customConditions": ["allow-ff-test-exports"],
},
"include": ["./**/*"],
"references": [
Expand Down
16 changes: 9 additions & 7 deletions packages/runtime/id-compressor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
}
},
"./internal/test-utils": {
"import": {
"types": "./lib/test/index.d.ts",
"default": "./lib/test/index.js"
},
"require": {
"types": "./dist/test/index.d.ts",
"default": "./dist/test/index.js"
"allow-ff-test-exports": {
"import": {
"types": "./lib/test/index.d.ts",
"default": "./lib/test/index.js"
},
"require": {
"types": "./dist/test/index.d.ts",
"default": "./dist/test/index.js"
}
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions packages/test/mocha-test-setup/mocharc-common.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function getFluidTestMochaConfig(packageDir, additionalRequiredModules, testRepo
"recursive": true,
"require": requiredModulePaths,
"unhandled-rejections": "strict",
// Allow test-only indexes to be imported. Search the FF repo for package.json files with this condition to see example usage.
"node-option": "conditions=allow-ff-test-exports",
// Performance tests benefit from having access to GC, and memory tests require it.
// Exposing it here avoids all packages which do perf testing from having to expose it.
"v8-expose-gc": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/test/test-end-to-end-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"test:realsvc:local:report:full": "cross-env fluid__test__backCompat=FULL npm run test:realsvc:local --",
"test:realsvc:odsp": "npm run test:realsvc:run -- --driver=odsp --timeout=20s",
"test:realsvc:odsp:report": "npm run test:realsvc:odsp --",
"test:realsvc:r11s": "npm run test:realsvc:run -- --driver=r11s --timeout=20s --use-openssl-ca",
"test:realsvc:r11s": "npm run test:realsvc:run -- --driver=r11s --timeout=20s",
"test:realsvc:r11s:docker": "npm run test:realsvc:run -- --driver=r11s --r11sEndpointName=docker --timeout=20s",
"test:realsvc:routerlicious": "npm run test:realsvc:r11s",
"test:realsvc:routerlicious:report": "npm run test:realsvc:r11s --",
Expand Down
9 changes: 9 additions & 0 deletions packages/test/test-end-to-end-tests/src/test/.mocharc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@
const packageDir = `${__dirname}/../..`;
const getFluidTestMochaConfig = require("@fluid-private/test-version-utils/mocharc-common");
const config = getFluidTestMochaConfig(packageDir);

// The 'use-openssl-ca' node option used to be passed as a flag in the npm script in package.json, but
// adding node-option to the base mocharc-common.cjs caused it to be ignored, so we need to append it here.
if (config["node-option"] === undefined) {
config["node-option"] = "use-openssl-ca";
} else {
config["node-option"] += ",use-openssl-ca";
}

module.exports = config;

0 comments on commit ee2267c

Please sign in to comment.