Skip to content

Commit 6d931ce

Browse files
committed
docs: source code docs
fixes SAP-archive#12
1 parent 374496c commit 6d931ce

File tree

14 files changed

+46
-20
lines changed

14 files changed

+46
-20
lines changed

.eslintrc.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ module.exports = {
22
// Common settings for JS Files.
33
extends: [
44
"eslint:recommended",
5-
// TODO: inspect: https://mysticatea.github.io/eslint-plugin-eslint-comments/rules/require-description.html usage.
65
"plugin:eslint-comments/recommended",
7-
// Disables all formatting related rules as formatting is handled by prettier.
6+
// Disables all formatting related rules as formatting is handled by prettier, not eslint.
87
"prettier",
98
],
109
parserOptions: {
@@ -17,14 +16,16 @@ module.exports = {
1716
mocha: true,
1817
node: true,
1918
},
19+
rules: {
20+
"eslint-comments/require-description": ["error", { ignore: [] }],
21+
},
2022
overrides: [
2123
{
2224
// For pure-java script sub-packages and general scripts (in any package).
2325
files: ["*.js"],
2426
},
2527
{
26-
// TODO: does this also scan d.ts files?
27-
// For sub-packages using TypeScript (libraries/VSCode Exts).
28+
// For sub-packages using TypeScript (libraries/VSCode Exts) && TypeScript definitions (d.ts)
2829
files: ["*.ts"],
2930
plugins: ["@typescript-eslint"],
3031
parser: "@typescript-eslint/parser",

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ The consumption process is currently a **manual** step by step guide.
7373
1. Adjust the [.eslintrc.js](./.eslintrc.js) configuration.
7474

7575
- Remove `overrides` sections for no longer relevant file types:
76-
- `["*.ts"]` --> if your monorepo does not contain any TypeScript projects.
76+
- `["*.ts"]` --> if your monorepo does not contain any TypeScript sources (including `.d.ts` files).
7777
- `["*.vue"]` --> if your monorepo does not contain any vue frontend projects.
7878
- Remove `dev-depedencies` from the [root package.json](./package.json)
7979
- `@typescript-eslint/*` --> if your monorepo does not contain any TypeScript projects.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* A new Mocha configuration is needed because the JavaScript test files are located
3-
* in a different folder in a pure ECMAScript project.
4-
*/
51
module.exports = {
62
spec: "./test/**/*spec.js",
73
};

packages/npm_package_typescript_library/test/implementation-matches-public-api.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ type AssertIsSubSet<SUBSET extends SUPERSET, SUPERSET> = [SUBSET, SUPERSET];
88
// We can perform logical assertions on the API vs Impel
99
// using discrete math semantics (subsets/supersets)
1010
// See: https://www.typescriptlang.org/docs/handbook/type-compatibility.html
11-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
11+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- the definition is also the usage
1212
type EnsureAllDeclaredAreExposedAtRuntime = AssertIsSubSet<
1313
typeof implementation,
1414
typeof publicApi
1515
>;
1616

17-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
17+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- the definition is also the usage
1818
type EnsureNoRedundantAreExposedAtRuntime = AssertIsSubSet<
1919
typeof publicApi,
2020
typeof implementation

packages/vscode_simple_ext/src/extension.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { window } from "vscode";
2+
// Using **sibling** libraries from our monorepo.
23
import { multiply } from "@ecmascript_monorepo_template/npm_package_javascript_library";
34
import { add } from "@ecmascript_monorepo_template/npm_package_typescript_library";
45

packages/vue_frontend_rpc/local-dev/backend-mock.js

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ const {
66

77
const ASYNC_NOOP = async () => {};
88

9+
/**
10+
* A Backend mock using WebSockets.
11+
* Note that this class does not include the RPC end points logic.
12+
* Those can be passed via the constructors `opts` to implement different types of backend mocks, e.g:
13+
* - In Memory mock for testing.
14+
* - Mock using a real (hard-coded path) file for local "playground".
15+
*/
916
class BackendMock {
1017
/**
1118
* @param [opts] {object}

packages/vue_frontend_rpc/local-dev/fs-backend-mock.js packages/vue_frontend_rpc/local-dev/run-fs-backend-mock.js

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const editorFilePath = resolve(__dirname, "./person-details.json");
66
const editorFileText = readFileSync(editorFilePath, "utf-8");
77
let editorFileObject = JSON.parse(editorFileText);
88

9+
/**
10+
* Websocket Backend mock using a real file (`./person-details.json`)
11+
* This is used as a playground during local development to enable fast feedback loops.
12+
*/
913
new BackendMock({
1014
onFrontendReady: async () => {
1115
return editorFileObject;

packages/vue_frontend_rpc/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"test": "vue-cli-service test:unit ./test/**/*spec.js",
1313
"coverage": "nyc vue-cli-service test:unit ./test/**/*spec.js",
1414
"serve": "vue-cli-service serve --port=8090",
15-
"backend:mock": "node local-dev/fs-backend-mock.js"
15+
"backend:mock": "node local-dev/run-fs-backend-mock.js"
1616
},
1717
"dependencies": {
1818
"core-js": "^3.6.5",

packages/vue_frontend_rpc/src/components/person-form.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ export default {
7777
methods: {
7878
// we cannot test VSCode related flow without VSCode.
7979
setupVSCodeRpc: /* istanbul ignore next */ function () {
80-
// TODO: comment `acquireVsCodeApi` can only be called once.
80+
// `acquireVsCodeApi()` can only be invoked once, so we are "saving" it's result
81+
// on the `window` object in case we will need it again.
8182
window.vscode = acquireVsCodeApi();
82-
// TODO: why does this constructor needs to be passed the window object?
8383
rpc = new RpcBrowser(window, window.vscode);
8484
},
8585
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// During tests sources are compiled on the fly
2-
// This debugger statement provides our IDE with a little grace period
3-
// so it will be able to attach the breakpoints in time.
4-
// eslint-disable-next-line no-debugger
1+
/**
2+
* During tests sources are compiled on the fly
3+
* This debugger statement provides our IDE with a little grace period
4+
* so it will be able to attach the breakpoints in time.
5+
*/
6+
// eslint-disable-next-line no-debugger -- see above block comment
57
debugger;

packages/vue_frontend_rpc/test/functional/initial-data-visualization.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe("The Person Form", () => {
1212

1313
before(async () => {
1414
port = await getPort({ port: getPort.makeRange(9000, 10000) });
15+
// Start an in-memory websocket backend mock for this test.
1516
backendMock = new BackendMock({
1617
port: port,
1718
onFrontendReady: async () => {
@@ -32,6 +33,10 @@ describe("The Person Form", () => {
3233
// - Enable awaiting for the initialization logic as it seems
3334
// we cannot "await" for Vue life-cycle methods (e.g created) in tests.
3435
await wrapper.vm.setupWsRPC(port);
36+
37+
// Inspect the frontend successfully invoked `onFrontendReady` and received the expected data back.
38+
// - Note this is an (almost) productive functional flow, not a pure unit test.
39+
// We have a real frontend and backend communicating with RPC over a websocket.
3540
const firstNameInput = wrapper.find("#firstName");
3641
expect(firstNameInput.element.value).to.eql("Jane");
3742
const lastNameInput = wrapper.find("#lastName");

packages/vue_frontend_rpc/test/functional/saving-new-data.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ describe("The Person Form", () => {
99
describe("saving new data flow", () => {
1010
let backendMock;
1111
let port;
12+
// Our backend and frontend both run under the same node.js process in this test.
13+
// However as they communicate with RPC over websockets they don't share the same "promise chains".
14+
// We use a deferred promise to resolve async waiting during the tests.
15+
// Other approaches are documented here: https://vue-test-utils.vuejs.org/guides/#testing-asynchronous-behavior
1216
let saveDeferred = pDefer();
1317

1418
before(async () => {
@@ -52,6 +56,9 @@ describe("The Person Form", () => {
5256
await countryInput.setValue("SadLand");
5357
const saveButton = wrapper.find("#saveButton");
5458
saveButton.trigger("click");
59+
// Inspect the backend successfully received the expected data on `save` rpc call.
60+
// - Note this is an (almost) productive functional flow, not a pure unit test.
61+
// We have a real frontend and backend communicating with RPC over a websocket.
5562
await saveDeferred.promise;
5663
});
5764

scripts/merge-coverage.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/**
2-
* based on https://github.com/istanbuljs/istanbuljs/blob/1fe490e51909607137ded25b1688581c9fd926cd/monorepo-merge-reports.js
2+
* This script will create a **merged** coverage reports from all sub-packages.
3+
* This report will can be found at the root `coverage` dir and will also be uploaded to coveralls.io
4+
* - based on https://github.com/istanbuljs/istanbuljs/blob/1fe490e51909607137ded25b1688581c9fd926cd/monorepo-merge-reports.js
35
*/
46
const { dirname, basename, join, resolve } = require("path");
57
const { spawnSync } = require("child_process");
@@ -35,6 +37,7 @@ glob.sync("packages/*/.nyc_output").forEach((nycOutput) => {
3537
}
3638
});
3739

40+
// Create merged report
3841
const { status, stderr } = spawnSync(
3942
resolve("node_modules", ".bin", "nyc"),
4043
["report", "--reporter=lcov"],

webpack.config.vscode.base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const config = {
1111
target: "node",
1212
devtool: "source-map",
1313
resolve: {
14-
// Solution for sibling package resolution inside mono-repo
14+
// Solution for sibling package resolution inside a monorepo
1515
modules: [
1616
path.resolve(__dirname, "node_modules"),
1717
path.resolve(__dirname, "../node_modules"),

0 commit comments

Comments
 (0)