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

Convert @fluid-example/table-document tests to use esnext modules #15939

Merged
merged 1 commit into from
Jun 12, 2023
Merged
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
12 changes: 12 additions & 0 deletions examples/data-objects/table-document/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -11,4 +11,16 @@ module.exports = {
rules: {
"@typescript-eslint/strict-boolean-expressions": "off",
},
overrides: [
{
// Rules only for test files
files: ["*.spec.ts", "src/test/**"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. There should be no *.spec.ts files outside src/test/ anyway, right? Not 100% sure about the glob syntax, if it's incorrect then just keep src/test/**?

Suggested change
files: ["*.spec.ts", "src/test/**"],
files: ["src/test/**/*.spec.ts"],

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like we use this glob in basically all our other packages with "test-only overrides". i'd prefer to keep that consistent over some simplification. We do want non-.spec files inside the test-folder to be exempted as well though, so if we were to change it, it should be src/test/**

rules: {
// ESLint's resolver doesn't resolve relative imports of ESNext modules correctly, since
// it resolves the path relative to the .ts file (and assumes a file with a .js extension
// should exist there)
"import/no-unresolved": ["error", { ignore: ["^\\.(.*)\\.js$"] }],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd love to make eslint's module resolver understand these imports, but I'm not sure it's possible out of the box (we'd have to maintain our own resolver, and I'm not sure if it would be a trivial wrapper over the base node resolver or not). I don't think this rule provides particularly high value for relative imports though, so IMO it's not the worst.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone must have written a solution for this already, right? Typescript transpiled to a different folder + ESM should be a common scenario by now...? Can be addressed separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for prodding me to look into this again. I think we can actually make this work nicely by removing eslint-plugin-unused-imports, transitioning to eslint-plugin-import, and updating our import resolve to be eslint-import-resolver-typescript (where the default extensionAlias should work perfectly). that'll require a release of the common lint config, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
},
],
};
1 change: 1 addition & 0 deletions examples/data-objects/table-document/README.md
Original file line number Diff line number Diff line change
@@ -20,3 +20,4 @@ For example, to support a feature like simple user attribution, the app can appe

Being an example, this package should have `private: true` in `package.json` but alas there's one consumer of Fluid
taking a dependency on it, so we can't do that yet.
Once it can be converted, or once that consumer confirms they don't need both ESNext and CommonJS modules, it should also drop the CommonJS build (this has already been done for the package's tests, but not its public API).
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ import { strict as assert } from "assert";
import { requestFluidObject } from "@fluidframework/runtime-utils";
import { ITestObjectProvider } from "@fluidframework/test-utils";
import { describeLoaderCompat } from "@fluid-internal/test-version-utils";
import { TableDocument } from "../document";
import { TableSlice } from "../slice";
import { TableDocumentItem } from "../table";
import { TableDocument } from "../document.js";
import { TableSlice } from "../slice.js";
import { TableDocumentItem } from "../table.js";

describeLoaderCompat("TableDocument", (getTestObjectProvider) => {
let tableDocument: TableDocument;
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ import { IFluidDataStoreContext } from "@fluidframework/runtime-definitions";
import { requestFluidObject } from "@fluidframework/runtime-utils";
import { ITestObjectProvider } from "@fluidframework/test-utils";
import { describeLoaderCompat } from "@fluid-internal/test-version-utils";
import { ITable } from "../table";
import { TableDocument } from "../document";
import { createTableWithInterception } from "../interception";
import { ITable } from "../table.js";
import { TableDocument } from "../document.js";
import { createTableWithInterception } from "../interception/index.js";

describeLoaderCompat("Table Document with Interception", (getTestObjectProvider) => {
describe("Simple User Attribution", () => {
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
"types": ["node", "mocha"],
"declaration": false,
"declarationMap": false,
"module": "esnext",
},
"include": ["./**/*"],
"references": [