@usestrider/vitest 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/VitestBrowser.d.ts +15 -7
- package/dist/VitestBrowser.d.ts.map +1 -1
- package/dist/VitestBrowser.js +49 -41
- package/dist/VitestBrowser.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/VitestBrowser.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The Vitest adapter
|
|
3
|
-
* Effect; peer dependency: `vitest` 5).
|
|
2
|
+
* The Vitest adapter: a browser layer for `@effect/vitest`, with `TestRun` for the test that's running.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
4
|
+
* `VitestBrowser.layer` passes the backend's layer through unchanged. The package's peer dependency is `vitest` 5.
|
|
6
5
|
*
|
|
7
6
|
* @stability unstable
|
|
8
7
|
* @since 0.1.0
|
|
@@ -23,20 +22,29 @@ declare module "vitest" {
|
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
25
|
+
* Provides the backend you pass, unchanged, plus `TestRun` for the current test.
|
|
27
26
|
*
|
|
28
|
-
* **
|
|
27
|
+
* **Details**
|
|
28
|
+
*
|
|
29
|
+
* The browser starts where the layer is built: given to `@effect/vitest`'s `layer`, once for the block, whose tests
|
|
30
|
+
* share it; provided to one effect, as below, once for that effect.
|
|
31
|
+
*
|
|
32
|
+
* **Example** (Providing a browser to a test)
|
|
29
33
|
*
|
|
30
34
|
* ```ts import.meta.vitest
|
|
31
|
-
* import { Effect } from "effect"
|
|
32
35
|
* import { Browser } from "@usestrider/browser"
|
|
33
36
|
* import { Chromium } from "@usestrider/browser/chromium"
|
|
34
37
|
* import { VitestBrowser } from "@usestrider/vitest"
|
|
38
|
+
* import { Effect } from "effect"
|
|
35
39
|
*
|
|
36
40
|
* const test = Effect.scoped(Effect.gen(function*() {
|
|
37
41
|
* const page = yield* Browser.newPage({ focus: "emulated" })
|
|
38
42
|
* yield* page.goto("https://shop.example.com")
|
|
39
|
-
* })).pipe(
|
|
43
|
+
* })).pipe(
|
|
44
|
+
* Effect.provide(
|
|
45
|
+
* VitestBrowser.layer(Chromium.layer({ executablePath: "/usr/bin/chromium" }))
|
|
46
|
+
* )
|
|
47
|
+
* )
|
|
40
48
|
* ```
|
|
41
49
|
*
|
|
42
50
|
* @stability unstable
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VitestBrowser.d.ts","sourceRoot":"","sources":["../src/VitestBrowser.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"VitestBrowser.d.ts","sourceRoot":"","sources":["../src/VitestBrowser.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,KAAK,OAAO,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAElD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,oBAAoB;QAC5B,qBAAqB,EAAE;YACrB,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAA;YACpC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;YAC/C,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC;gBAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;aAAE,CAAC,CAAA;SACrF,CAAA;KACF;CACF;AA8DD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,WACf,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,KAC1C,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAkE,CAAA"}
|
package/dist/VitestBrowser.js
CHANGED
|
@@ -3,69 +3,77 @@ import * as Effect from "effect/Effect";
|
|
|
3
3
|
import * as Layer from "effect/Layer";
|
|
4
4
|
import { recordArtifact, TestRunner } from "vitest";
|
|
5
5
|
/** The test's path: its file, then each suite, then the test. */
|
|
6
|
-
const pathOf =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return [test.file.name, ...names].join(" > ");
|
|
6
|
+
const pathOf = test => {
|
|
7
|
+
const names = [test.name];
|
|
8
|
+
for (let suite = test.suite; suite !== undefined; suite = suite.suite) {
|
|
9
|
+
if (suite.name !== "") names.unshift(suite.name);
|
|
10
|
+
}
|
|
11
|
+
return [test.file.name, ...names].join(" > ");
|
|
13
12
|
};
|
|
14
|
-
const env =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
shard: env("VITEST_SHARD")
|
|
13
|
+
const env = name => globalThis.process?.env?.[name] ?? "";
|
|
14
|
+
const infoOf = test => new TestRun.TestInfo({
|
|
15
|
+
project: test?.file.projectName ?? "",
|
|
16
|
+
file: test?.file.filepath ?? "",
|
|
17
|
+
id: test === undefined ? "" : pathOf(test),
|
|
18
|
+
attempt: test?.result?.retryCount ?? 0,
|
|
19
|
+
worker: env("VITEST_POOL_ID"),
|
|
20
|
+
shard: env("VITEST_SHARD")
|
|
23
21
|
});
|
|
24
22
|
const contentType = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
Trace: "application/zip",
|
|
24
|
+
Har: "application/json",
|
|
25
|
+
Screenshot: "image/png"
|
|
28
26
|
};
|
|
29
27
|
/** `TestRun` for Vitest: the current test, read each time, and its artifacts. */
|
|
30
28
|
const testRun = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
})
|
|
29
|
+
get info() {
|
|
30
|
+
return infoOf(TestRunner.getCurrentTest());
|
|
31
|
+
},
|
|
32
|
+
attach: artifact => Effect.suspend(() => {
|
|
33
|
+
const test = TestRunner.getCurrentTest();
|
|
34
|
+
if (test === undefined) {
|
|
35
|
+
return Effect.logWarning(`TestRun.attach: no test is running, so ${artifact.path} wasn't attached`);
|
|
36
|
+
}
|
|
37
|
+
const type = artifact._tag === "Screenshot" && /\.jpe?g$/i.test(artifact.path) ? "image/jpeg" : contentType[artifact._tag];
|
|
38
|
+
return Effect.tryPromise(() => recordArtifact(test, {
|
|
39
|
+
type: "@usestrider/browser",
|
|
40
|
+
artifact: artifact._tag,
|
|
41
|
+
attachments: [{
|
|
42
|
+
path: artifact.path,
|
|
43
|
+
contentType: type
|
|
44
|
+
}]
|
|
45
|
+
})).pipe(Effect.asVoid, Effect.catch(error => Effect.logWarning(`TestRun.attach: Vitest didn't attach ${artifact.path}: ${error.message}`)));
|
|
46
|
+
})
|
|
48
47
|
};
|
|
49
48
|
/**
|
|
50
|
-
*
|
|
49
|
+
* Provides the backend you pass, unchanged, plus `TestRun` for the current test.
|
|
50
|
+
*
|
|
51
|
+
* **Details**
|
|
51
52
|
*
|
|
52
|
-
*
|
|
53
|
+
* The browser starts where the layer is built: given to `@effect/vitest`'s `layer`, once for the block, whose tests
|
|
54
|
+
* share it; provided to one effect, as below, once for that effect.
|
|
55
|
+
*
|
|
56
|
+
* **Example** (Providing a browser to a test)
|
|
53
57
|
*
|
|
54
58
|
* ```ts import.meta.vitest
|
|
55
|
-
* import { Effect } from "effect"
|
|
56
59
|
* import { Browser } from "@usestrider/browser"
|
|
57
60
|
* import { Chromium } from "@usestrider/browser/chromium"
|
|
58
61
|
* import { VitestBrowser } from "@usestrider/vitest"
|
|
62
|
+
* import { Effect } from "effect"
|
|
59
63
|
*
|
|
60
64
|
* const test = Effect.scoped(Effect.gen(function*() {
|
|
61
65
|
* const page = yield* Browser.newPage({ focus: "emulated" })
|
|
62
66
|
* yield* page.goto("https://shop.example.com")
|
|
63
|
-
* })).pipe(
|
|
67
|
+
* })).pipe(
|
|
68
|
+
* Effect.provide(
|
|
69
|
+
* VitestBrowser.layer(Chromium.layer({ executablePath: "/usr/bin/chromium" }))
|
|
70
|
+
* )
|
|
71
|
+
* )
|
|
64
72
|
* ```
|
|
65
73
|
*
|
|
66
74
|
* @stability unstable
|
|
67
75
|
* @category layers
|
|
68
76
|
* @since 0.1.0
|
|
69
77
|
*/
|
|
70
|
-
export const layer =
|
|
78
|
+
export const layer = backend => Layer.merge(backend, Layer.succeed(TestRun.TestRun, testRun));
|
|
71
79
|
//# sourceMappingURL=VitestBrowser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VitestBrowser.js","
|
|
1
|
+
{"version":3,"file":"VitestBrowser.js","names":[],"sources":["../src/VitestBrowser.ts"],"sourcesContent":[null],"mappings":"AASA,SAAS,OAAO,QAAQ,0BAA0B;AAClD,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,SAAS,cAAc,EAAE,UAAU,QAAQ,QAAQ;AAcnD;AACA,MAAM,MAAM,GAAI,IAAgB,IAAY;EAC1C,MAAM,KAAK,GAAkB,CAAC,IAAI,CAAC,IAAI,CAAC;EACxC,KAAK,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,EAAE,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE;IACrE,IAAI,KAAK,CAAC,IAAI,KAAK,EAAE,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;EAClD;EACA,OAAO,CAAC,IAA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9B,OAAO,MAAM,CAAC,UAAU,CAAC,MACvB,cAAc,CAAC,IAAI,EAAE;MACnB,IAAI,EAAE,qBAAqB;MAC3B,QAAQ,EAAE,QAAQ,CAAC,IAAI;MACvB,WAAW,EAAE,CAAC;QAAE,IAAI,EAAE,QAAQ,CAAC,IAAI;QAAE,WAAW,EAAE;MAAI,CAAE;KACzD,CAAC,CACH,CAAC,IAAI,CACJ,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,KAAK,CAAE,KAAK,IACjB,MAAM,CAAC,UAAU,CAAC,wCAAwC,QAAQ,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAC7F,CACF;EACH,CAAC;CACJ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,OAAO,MAAM,KAAK,GAChB,OAA2C,IACc,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC","ignoreList":[]}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;AAKA;AAEA;;;;AAIA,OAAO,KAAK,aAAa,MAAM,oBAAoB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usestrider/vitest",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://usestrider.dev",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"provenance": true
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@usestrider/browser": "^0.1.
|
|
42
|
+
"@usestrider/browser": "^0.1.1",
|
|
43
43
|
"effect": "^4.0.6",
|
|
44
44
|
"vitest": "^5.0.5"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@usestrider/browser": "^0.1.
|
|
47
|
+
"@usestrider/browser": "^0.1.1",
|
|
48
48
|
"@usestrider/utils": "^0.0.0",
|
|
49
49
|
"effect": "^4.0.6",
|
|
50
50
|
"vitest": "^5.0.5"
|