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

feat(component-testing): implement mocks #1027

Open
wants to merge 1 commit 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
106 changes: 106 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "testplane",
"version": "8.20.5",
"description": "Tests framework based on mocha and wdio",
"main": "build/src/index.js",
"files": [
"build",
"typings"
Expand Down Expand Up @@ -34,6 +33,20 @@
"type": "git",
"url": "git://github.com/gemini-testing/testplane.git"
},
"exports": {
".": "./build/src/index.js",
"./mock": "./build/src/mock/index.js"
},
Comment on lines +36 to +39
Copy link
Member

@KuznetsovRoman KuznetsovRoman Nov 13, 2024

Choose a reason for hiding this comment

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

After that, people wouldn't have ability to import from somewhere else
Maybe we could get rid of it, return "main" and export "mock" from "testplane" so we could do this:

import { mock } from "testplane"

or something like that.

I think we shouldn't define exports section in package.json until testplane@9

"typesVersions": {
Copy link
Member Author

Choose a reason for hiding this comment

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

In order to correctly set paths to types

"*": {
"index": [
"build/src/index.d.ts"
],
"mock": [
"build/src/mock/index.d.ts"
]
}
},
"homepage": "https://testplane.io/",
"engines": {
"node": ">= 18.0.0"
Expand All @@ -56,6 +69,7 @@
"@jspm/core": "2.0.1",
"@types/debug": "4.1.12",
"@types/yallist": "4.0.4",
"@vitest/spy": "2.1.4",
"@wdio/globals": "8.39.0",
"@wdio/protocols": "8.38.0",
"@wdio/types": "8.39.0",
Expand All @@ -81,6 +95,7 @@
"mocha": "10.2.0",
"plugins-loader": "1.3.4",
"png-validator": "1.1.0",
"recast": "0.23.6",
Copy link
Member Author

Choose a reason for hiding this comment

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

Used in browser env in order to correctly modify ast tree to correctly work with mock

"resolve.exports": "2.0.2",
"sharp": "0.32.6",
"sizzle": "2.3.6",
Expand All @@ -90,6 +105,7 @@
"strftime": "0.10.2",
"strip-ansi": "6.0.1",
"temp": "0.8.3",
"tinyspy": "3.0.2",
"urijs": "1.19.11",
"url-join": "4.0.1",
"vite": "5.1.6",
Expand Down
19 changes: 19 additions & 0 deletions src/mock/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export * from "./vitest-spy";
import { isRunInBrowserEnv } from "../utils/browser";

// TODO: use from browser code when migrate to esm
type MockFactory = (originalImport?: unknown) => Promise<unknown>;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function mock(_moduleName: string, _factory?: MockFactory): void {
if (!isRunInBrowserEnv()) {
throw new Error('"mock" method is available only in browser environment');
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function unmock(_moduleName: string): void {
if (!isRunInBrowserEnv()) {
throw new Error('"unmock" method is available only in browser environment');
}
}
Loading
Loading