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

Isolates the use of browser-system for setting up virtual compilation environments #42

Merged
merged 14 commits into from
May 7, 2024
Merged
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: 1 addition & 1 deletion .github/workflows/protect-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
node-version: 20
- uses: pnpm/action-setup@v3
with:
version: 8
version: 9

- name: install
run: pnpm install --frozen-lockfile
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
node-version: 20
- uses: pnpm/action-setup@v3
with:
version: 8
version: 9

- name: install
run: pnpm install --frozen-lockfile
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
scope: "@quatico"
- uses: pnpm/action-setup@v3
with:
version: 8
version: 9

- name: install
run: pnpm install --frozen-lockfile
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = [
["@quatico/websmith-api", __dirname + "/packages/api/src"],
["@quatico/websmith-compiler", __dirname + "/packages/compiler/src"],
["@quatico/websmith-core", __dirname + "/packages/core/src"],
["@quatico/websmith-testing", __dirname + "/packages/testing/src"],
["@quatico/websmith-webpack", __dirname + "/packages/webpack/src"],
],
extensions: [".ts", ".js", ".jsx", ".json"],
Expand Down
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ module.exports = {
"@quatico/websmith-api": "<rootDir>/packages/api/src",
"@quatico/websmith-compiler": "<rootDir>/packages/compiler/src",
"@quatico/websmith-core": "<rootDir>/packages/core/src",
"@quatico/websmith-testing": "<rootDir>/packages/testing/src",
"@quatico/websmith-webpack": "<rootDir>/packages/webpack/src",
},
prettierPath: null,
modulePathIgnorePatterns: ["<rootDir>/packages/compiler/test/__mocks__/fs.ts"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
testRegex: "src/.*(test|spec)\\.(tsx?)$",
testRegex: "src/.*spec\\.(tsx?)$",
testEnvironmentOptions: { url: "http://localhost/" },
transform: {
"^.+\\.(js|ts)$": [
Expand Down
13 changes: 3 additions & 10 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
/* eslint-disable no-console */
import { createFs, resetFs } from "./packages/core/test/fusion-fs";
import { tsLibMocks } from "./packages/core/test/tsLibMocks";
import { tsLibMocks } from "./packages/testing/src/tsLibMocks";
import { readE2eTestData } from "./packages/test/src/test-data-helper";

tsLibMocks();

export { readE2eTestData };

console.debug = () => undefined;
console.info = () => undefined;
console.log = () => undefined;

jest.mock("fs", () => {
return createFs(jest.requireActual("fs"));
});

afterEach(() => {
jest.clearAllMocks();
resetFs();
});

export { readE2eTestData };
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
},
"devDependencies": {
"@cucumber/gherkin": "^28.0.0",
"@eslint/js": "^9.0.0",
"@nrwl/nx-cloud": "18.0.0",
"@nx/eslint-plugin": "^18.2.4",
"@swc/core": "1.4.14",
"@eslint/js": "^9.1.1",
"@nrwl/nx-cloud": "18.0.1",
"@nx/eslint-plugin": "^18.3.3",
"@swc/core": "1.5.0",
"@swc/jest": "0.2.36",
"@types/glob": "^8.1.0",
"@types/jest": "^29.5.12",
Expand All @@ -50,7 +50,7 @@
"concurrently": "^8.2.2",
"create-hash": "1.2.0",
"cross-env": "7.0.3",
"eslint": "^9.0.0",
"eslint": "^9.1.1",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.29.1",
Expand All @@ -62,7 +62,7 @@
"jest": "^29.7.0",
"license-check-and-add": "4.0.5",
"memfs": "^4.8.2",
"nx": "^18.2.4",
"nx": "^18.3.3",
"path": "0.12.7",
"prettier": "^3.2.5",
"quill-delta": "^5.1.0",
Expand All @@ -71,7 +71,7 @@
"ts-node": "^10.9.2",
"tslib": "2.6.2",
"typescript": "5.4.5",
"typescript-eslint": "^7.7.0",
"typescript-eslint": "^7.7.1",
"webpack": "^5.91.0"
},
"pnpm": {
Expand Down
10 changes: 5 additions & 5 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@
"dist": "pnpm clean && pnpm lint && pnpm test && cross-env-shell NODE_ENV=production \"pnpm build\""
},
"devDependencies": {
"@eslint/js": "^9.0.0",
"@nx/eslint-plugin": "^18.2.4",
"@swc/core": "1.4.14",
"@eslint/js": "^9.1.1",
"@nx/eslint-plugin": "^18.3.3",
"@swc/core": "1.5.0",
"@swc/jest": "0.2.36",
"@types/jest": "^29.5.12",
"concurrently": "^8.2.2",
"cross-env": "7.0.3",
"eslint": "^9.1.1",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.2.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-testing-library": "^6.2.2",
"eslint": "^9.0.0",
"globals": "^15.0.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"rimraf": "5.0.5",
"typescript": "5.4.5",
"typescript-eslint": "^7.7.0"
"typescript-eslint": "^7.7.1"
},
"peerDependencies": {
"typescript": "5.x"
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ module.exports = {
moduleNameMapper: {
"@quatico/websmith-api": "<rootDir>/../api/src",
"@quatico/websmith-core": "<rootDir>/../core/src",
"@quatico/websmith-testing": "<rootDir>/../testing/src",
},
prettierPath: null,
testRegex: "src/.*\\.spec\\.(j|t)s$",
setupFilesAfterEnv: ["<rootDir>/../../jest.setup.ts"],
testEnvironmentOptions: { url: "http://localhost/" },
Expand Down
11 changes: 6 additions & 5 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,28 @@
"dist": "cross-env-shell NODE_ENV=production \"pnpm clean && pnpm lint && pnpm test && pnpm build\""
},
"devDependencies": {
"@eslint/js": "^9.0.0",
"@nx/eslint-plugin": "^18.2.4",
"@swc/core": "1.4.14",
"@eslint/js": "^9.1.1",
"@nx/eslint-plugin": "^18.3.3",
"@quatico/websmith-testing": "workspace:^",
"@swc/core": "1.5.0",
"@swc/jest": "0.2.36",
"@types/jest": "^29.5.12",
"@types/minimist": "^1.2.5",
"@types/node": "^20.12.7",
"concurrently": "^8.2.2",
"cross-env": "7.0.3",
"eslint": "^9.1.1",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.2.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-testing-library": "^6.2.2",
"eslint": "^9.0.0",
"globals": "^15.0.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"rimraf": "5.0.5",
"typescript-eslint": "^7.7.0"
"typescript-eslint": "^7.7.1"
},
"dependencies": {
"@quatico/websmith-api": "workspace:^",
Expand Down
19 changes: 7 additions & 12 deletions packages/compiler/src/command.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access */
/*
* ---------------------------------------------------------------------------------------------
* Copyright (c) Quatico Solutions AG. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
* ---------------------------------------------------------------------------------------------
*/

import { WarnMessage } from "@quatico/websmith-api";
import { Compiler, CompilerAddon, createBrowserSystem, NoReporter } from "@quatico/websmith-core";
import { Compiler, CompilerAddon, NoReporter } from "@quatico/websmith-core";
import { compileSystem } from "@quatico/websmith-testing";
import { Command } from "commander";
import path from "path";
import ts from "typescript";
import { addCompileCommand, hasInvalidTargets } from "./command";
import { createOptions } from "./options";

let testSystem;
let testSystem: ts.System;

beforeEach(() => {
testSystem = emptySystem();
testSystem = compileSystem().fileSystem;
});

describe("addCompileCommand", () => {
Expand Down Expand Up @@ -139,6 +141,7 @@ describe("addCompileCommand", () => {

it("should yield watch compiler option w/ --watch cli argument", () => {
const target = new Compiler(createOptions({}, new NoReporter()));
target.registerWatch = jest.fn(); // prevent register of watch task

addCompileCommand(new Command(), target).parse(["--watch"], { from: "user" });

Expand Down Expand Up @@ -496,11 +499,3 @@ describe("hasInvalidTargets", () => {
).toBe(true);
});
});

const emptySystem = () => {
const result = createBrowserSystem();
result.writeFile("./tsconfig.json", "{}");
result.writeFile("./websmith.config.json", "{}");
result.createDirectory("./addons");
return result;
};
19 changes: 11 additions & 8 deletions packages/compiler/src/find-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,49 @@
* Licensed under the MIT License. See LICENSE in the project root for license information.
* ---------------------------------------------------------------------------------------------
*/
import { createBrowserSystem } from "@quatico/websmith-core";
import { compileSystem } from "@quatico/websmith-testing";
import { findConfigFile, findSassConfig } from "./find-config";

describe("findConfigFile", () => {
it("returns file name with path to existing file", () => {
const target = createBrowserSystem({
"tsconfig.json": JSON.stringify({}),
});
const { fileSystem: target } = compileSystem(
{
"tsconfig.json": JSON.stringify({}),
},
{ withDefaultFiles: false }
);

const actual = findConfigFile("./", target);

expect(actual).toBe("./tsconfig.json");
});

it("throws error with no existing config file", () => {
const target = createBrowserSystem({});
const { fileSystem: target } = compileSystem({}, { withDefaultFiles: false });

expect(() => findConfigFile("./", target)).toThrow("Could not find a valid 'tsconfig.json'.");
});
});

describe("findSassConfig", () => {
it("returns file name with path to existing file", () => {
const target = createBrowserSystem({ "sass.config.js": `{}` });
const { fileSystem: target } = compileSystem({ "sass.config.js": `{}` });

const actual = findSassConfig("sass.config.js", target);

expect(actual).toBe("/sass.config.js");
});

it("returns file name with path to custom existing file", () => {
const target = createBrowserSystem({ "expected.js": `{}` });
const { fileSystem: target } = compileSystem({ "expected.js": `{}` });

const actual = findSassConfig("expected.js", target);

expect(actual).toBe("/expected.js");
});

it("throws error with no existing config file", () => {
const target = createBrowserSystem({});
const { fileSystem: target } = compileSystem();

expect(() => findSassConfig("sass.config.js", target)).toThrow("Could not find a valid 'sass.config.js'.");
});
Expand Down
Loading