Skip to content

Commit b5a28ee

Browse files
committed
feature: plugma test command
Signed-off-by: Saulo Vallory <me@saulo.engineer>
1 parent 345525d commit b5a28ee

File tree

112 files changed

+3067
-8564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+3067
-8564
lines changed

packages/plugma/.vscode/settings.json

+65-66
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,67 @@
11
{
2-
"editor.formatOnSave": trueŹ
3-
"editor.defaultFormatter": "gplane.dprint2",
4-
"[javascript]": {
5-
"editor.defaultFormatter": "biomejs.biome"
6-
},
7-
"[typescript]": {
8-
"editor.defaultFormatter": "biomejs.biome"
9-
},
10-
"[json]": {
11-
"editor.defaultFormatter": "biomejs.biome"
12-
},
13-
"[svelte]": {
14-
"editor.defaultFormatter": "svelte.svelte-vscode"
15-
},
16-
"explorer.fileNesting.enabled": true,
17-
"explorer.fileNesting.patterns": {
18-
"Config Files.md": "biome.*, dprint.*, .env*, *.cjs, *.config.ts, *.setup.ts, .git*, *.config, *.config.json, *config.js, *config.mjs, *config.cjs, *config.ts, *config.toml, *config.yaml, *config.yml, *rc, *rc.json, *rc.js, *rc.mjs, *rc.cjs, *rc.ts, *rc.toml, *rc.yaml, *rc.yml, *ignore, Dockerfile*, docker-*, *.toml, package-lock.json, yarn.lock, pnpm-lock.yaml, .prototools, rollup.*, renovate.json, .size-limit.*, vitest*",
19-
"*.json": "${capture}.lock",
20-
"*.ts": "${capture}.test.ts"
21-
},
22-
"search.exclude": {
23-
"**/coverage": true,
24-
"**/dist": true,
25-
"**/node_modules": true
26-
},
27-
"typescript.enablePromptUseWorkspaceTsdk": true,
28-
"typescript.preferences.autoImportFileExcludePatterns": ["dist/**"],
29-
"typescript.tsdk": "node_modules/typescript/lib",
30-
"cSpell.words": [
31-
"@endindex",
32-
"antfu",
33-
"Automator",
34-
"biomejs",
35-
"clickoutside",
36-
"commitlint",
37-
"conventionalcommits",
38-
"dprint",
39-
"endindex",
40-
"Fong",
41-
"plugma",
42-
"stylelint",
43-
"texthighlight",
44-
"tokilabs",
45-
"typecheck"
46-
],
47-
"gutterpreview.enableReferenceLookup": true,
48-
"gutterpreview.currentColorForSVG": "#CCC",
49-
"svelte.enable-ts-plugin": true,
50-
"svelte-autoimport.doubleQuotes": false,
51-
"svelte.plugin.svelte.format.config.singleQuote": true,
52-
"prettier.jsxSingleQuote": true,
53-
"prettier.singleQuote": true,
54-
"yaml.format.singleQuote": true,
55-
"[jsonc]": {
56-
"editor.defaultFormatter": "biomejs.biome"
57-
},
58-
"editor.codeActionsOnSave": {
59-
"source.addMissingImports.ts": "always",
60-
"source.organizeImports": "always",
61-
"source.fixAll": "always",
62-
"source.fixAll.biome": "always",
63-
"source.organizeImports.biome": "always",
64-
"source.removeUnusedImports": "always",
65-
"source.sortImports": "always"
66-
},
67-
"vitest.rootConfig": "vitest.config.ts"
2+
"editor.formatOnSave": true,
3+
"editor.defaultFormatter": "gplane.dprint2",
4+
"[javascript]": {
5+
"editor.defaultFormatter": "biomejs.biome"
6+
},
7+
"[typescript]": {
8+
"editor.defaultFormatter": "biomejs.biome"
9+
},
10+
"[json]": {
11+
"editor.defaultFormatter": "biomejs.biome"
12+
},
13+
"[svelte]": {
14+
"editor.defaultFormatter": "svelte.svelte-vscode"
15+
},
16+
"explorer.fileNesting.enabled": true,
17+
"explorer.fileNesting.patterns": {
18+
"Config Files.md": "biome.*, dprint.*, .env*, *.cjs, *.config.ts, *.setup.ts, .git*, *.config, *.config.json, *config.js, *config.mjs, *config.cjs, *config.ts, *config.toml, *config.yaml, *config.yml, *rc, *rc.json, *rc.js, *rc.mjs, *rc.cjs, *rc.ts, *rc.toml, *rc.yaml, *rc.yml, *ignore, Dockerfile*, docker-*, *.toml, package-lock.json, yarn.lock, pnpm-lock.yaml, .prototools, rollup.*, renovate.json, .size-limit.*, vitest*",
19+
"*.json": "${capture}.lock",
20+
"*.ts": "${capture}.test.ts"
21+
},
22+
"search.exclude": {
23+
"**/coverage": true,
24+
"**/dist": true,
25+
"**/node_modules": true
26+
},
27+
"typescript.enablePromptUseWorkspaceTsdk": true,
28+
"typescript.preferences.autoImportFileExcludePatterns": ["dist/**"],
29+
"typescript.tsdk": "node_modules/typescript/lib",
30+
"cSpell.words": [
31+
"@endindex",
32+
"antfu",
33+
"Automator",
34+
"biomejs",
35+
"clickoutside",
36+
"commitlint",
37+
"conventionalcommits",
38+
"dprint",
39+
"endindex",
40+
"Fong",
41+
"plugma",
42+
"stylelint",
43+
"texthighlight",
44+
"tokilabs",
45+
"typecheck"
46+
],
47+
"gutterpreview.enableReferenceLookup": true,
48+
"gutterpreview.currentColorForSVG": "#CCC",
49+
"svelte.enable-ts-plugin": true,
50+
"svelte-autoimport.doubleQuotes": false,
51+
"svelte.plugin.svelte.format.config.singleQuote": true,
52+
"prettier.jsxSingleQuote": true,
53+
"prettier.singleQuote": true,
54+
"yaml.format.singleQuote": true,
55+
"[jsonc]": {
56+
"editor.defaultFormatter": "biomejs.biome"
57+
},
58+
"editor.codeActionsOnSave": {
59+
// "source.organizeImports": "always",
60+
// "source.fixAll": "always",
61+
// "source.fixAll.biome": "always",
62+
// "source.organizeImports.biome": "always",
63+
// "source.removeUnusedImports": "always",
64+
// "source.sortImports": "always"
65+
},
66+
"vitest.rootConfig": "vitest.config.ts"
6867
}

packages/plugma/apps/plugma-runtime/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
*/
1313

1414
import {
15-
handleDeleteClientStorage,
16-
handleDeleteRootPluginData,
17-
handleHideToolbar,
18-
handleMaximizeWindow,
19-
handleMinimizeWindow,
20-
handleSaveWindowSettings
15+
handleDeleteClientStorage,
16+
handleDeleteRootPluginData,
17+
handleHideToolbar,
18+
handleMaximizeWindow,
19+
handleMinimizeWindow,
20+
handleSaveWindowSettings,
2121
} from './handlers/index.js';
2222

2323
import type { PlugmaRuntimeData } from './types.js';

packages/plugma/apps/tsconfig.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@
2121
"#utils": ["../src/utils/index.ts"],
2222
"#utils/*": ["../src/utils/*"],
2323
"#vite-plugins": ["../src/vite-plugins/index.ts"],
24-
"#vite-plugins/*": ["../src/vite-plugins/*"]
24+
"#vite-plugins/*": ["../src/vite-plugins/*"],
25+
"#testing": ["../src/testing/index.ts"],
26+
"#testing/*": ["../src/testing/*"]
2527
}
2628
},
27-
"include": ["./**/*.js", "./**/*.ts", "./**/*.svelte"]
29+
"include": [
30+
"./**/*.js",
31+
"./**/*.ts",
32+
"./**/*.svelte",
33+
"../src/testing/execute-assertions.ts"
34+
]
2835
}
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Core testing functions
2+
export const test = undefined;
3+
export const it = undefined;
4+
export const describe = undefined;
5+
export const suite = undefined;
6+
export const expect = undefined;
7+
export const assert = undefined;
8+
export const vitest = undefined;
9+
export const vi = undefined;
10+
11+
// Lifecycle hooks
12+
export const beforeAll = undefined;
13+
export const beforeEach = undefined;
14+
export const afterAll = undefined;
15+
export const afterEach = undefined;
16+
17+
// Mocking utilities
18+
export const mocked = undefined;
19+
export const fn = undefined;
20+
export const spyOn = undefined;
21+
22+
// Advanced features
23+
export const waitFor = undefined;
24+
export const waitUntil = undefined;
25+
export const isFakeTimers = undefined;
26+
export const useFakeTimers = undefined;
27+
export const useRealTimers = undefined;

sandbox-bkp/src/testing/test-runner.ts packages/plugma/archive/testing-poc/test-runner.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { test as vitestTest } from "vitest";
2+
import { executeAssertions } from "./expect";
23
import { disableLoggger as logger } from "./logger";
4+
import { registry } from "./registry";
35
import type { TestFn } from "./types";
4-
import { executeAssertions } from "./expect";
56
import { testClient } from "./ws-client";
6-
import { registry } from "./registry";
77

88
/**
99
* Configuration for test execution
@@ -84,23 +84,22 @@ export const test: TestFn = async (name, fn) => {
8484
}
8585

8686
if (!vitestTest) {
87-
throw new Error("Vitest is not available in this environment");
87+
throw new Error("Vitest is not available");
8888
}
8989

9090
// In Node: Create a Vitest test that sends a message to Figma
9191
return vitestTest(name, TEST_CONFIG, async () => {
9292
logger.debug("Running test:", name);
9393
const testRunId = `${name}-${Date.now()}`;
94-
let assertionCode: string | null = null;
94+
const assertionCode: string | null = null;
9595

9696
try {
9797
// Setup handler before sending the message
98-
const assertionsPromise = new Promise<void>((resolve, reject) => {
98+
const assertionsPromise = new Promise<string>((resolve, reject) => {
9999
testClient.waitForTestResult(testRunId).then(
100100
(response) => {
101101
if (response.type === "TEST_ASSERTIONS") {
102-
assertionCode = response.assertionCode;
103-
resolve();
102+
resolve(response.assertionCode);
104103
} else {
105104
reject(
106105
new TestExecutionError(
@@ -125,12 +124,13 @@ export const test: TestFn = async (name, fn) => {
125124
logger.debug("[test-runner] 📮 RUN_TEST:", runTestMessage);
126125

127126
// Send the message and wait for assertions
128-
await testClient.send(runTestMessage);
129-
await withTimeout(assertionsPromise, TEST_CONFIG.timeout, name);
127+
const assertionCodeResult = await withTimeout(
128+
assertionsPromise,
129+
TEST_CONFIG.timeout,
130+
name,
131+
);
130132

131-
if (assertionCode) {
132-
executeAssertions(assertionCode.split(";\n").filter(Boolean));
133-
}
133+
executeAssertions(assertionCodeResult.split(";\n").filter(Boolean));
134134
} catch (error) {
135135
if (error instanceof TestTimeoutError) {
136136
logger.error("Test timed out:", error.message);
File renamed without changes.

sandbox-bkp/src/testing/ws-client.ts packages/plugma/archive/testing-poc/ws-client.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { TestMessage } from "./types";
21
import { disableLoggger as logger } from "./logger";
2+
import type { TestMessage } from "./types";
33

44
declare global {
55
var testWs: WebSocket | undefined;
@@ -158,15 +158,17 @@ export class TestClient {
158158
}
159159
}
160160

161-
// Also resolve the original send promise
162-
const index = this.messageQueue.findIndex(
163-
(item) => item.testRunId === message.testRunId,
164-
);
165-
if (index !== -1) {
166-
const { resolve, timeoutId } = this.messageQueue[index];
167-
clearTimeout(timeoutId);
168-
this.messageQueue.splice(index, 1);
169-
resolve();
161+
if ("testRunId" in message) {
162+
// Also resolve the original send promise
163+
const index = this.messageQueue.findIndex(
164+
(item) => item.testRunId === message.testRunId,
165+
);
166+
if (index !== -1) {
167+
const { resolve, timeoutId } = this.messageQueue[index];
168+
clearTimeout(timeoutId);
169+
this.messageQueue.splice(index, 1);
170+
resolve();
171+
}
170172
}
171173
} catch (error) {
172174
logger.error("[ws-client] Error handling message:", error);

0 commit comments

Comments
 (0)