@thednp/dommatrix 2.0.7 → 2.0.8

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.
@@ -1,34 +1,36 @@
1
- /// <reference types="cypress" />
1
+ import { expect, it, describe, vi, beforeEach, afterEach } from 'vitest';
2
+ import { getExampleDOM } from './fixtures/getExampleDom';
2
3
 
3
- import CSSMatrix from '../../src/index';
4
- import type { Matrix, Matrix3d } from '../../src/types';
5
- import testSamples from '../fixtures/testSamples';
4
+ import CSSMatrix from '../src/index';
5
+ import type { Matrix, Matrix3d } from '../src/types';
6
+ import testSamples from './fixtures/testSamples';
6
7
 
7
8
  const roundTo4 = (x: number) => Math.round(x * 10000) / 10000
8
9
 
9
10
  describe('DOMMatrix Class Test', () => {
10
-
11
- beforeEach(() => {
12
- cy.visit('cypress/test.html')
11
+ let container: HTMLElement;
12
+ beforeEach(async () => {
13
+ container = getExampleDOM();
14
+ await vi.waitUntil(() => container.querySelector('div') !== null, { timeout: 150 });
15
+ });
16
+ afterEach(async () => {
17
+ document.documentElement.innerHTML = '';
13
18
  });
14
19
 
15
20
  it('Test init with no parameter, expect same output as native DOMMatrix', () => {
16
21
  const css = new CSSMatrix();
17
22
  const css1 = new CSSMatrix().setMatrixValue();
18
23
  const dom = new DOMMatrix();
19
- cy.wrap(css).as('css')
20
- .get('@css').its('is2D').should('equal', dom.is2D)
21
- .get('@css').its('isIdentity').should('equal', dom.isIdentity)
22
- .get('@css').should(($this) => {
23
- expect(JSON.stringify($this)).to.equal(JSON.stringify(dom));
24
- expect(JSON.stringify($this)).to.equal(JSON.stringify(css1));
25
- })
24
+
25
+ expect(css.is2D).to.equal(dom.is2D);
26
+ expect(css.isIdentity).to.equal(dom.isIdentity);
27
+ expect(JSON.stringify(css)).to.equal(JSON.stringify(dom));
28
+ expect(JSON.stringify(css)).to.equal(JSON.stringify(css1));
26
29
  });
27
30
 
28
31
  it('Test init with invalid array, expect error', () => {
29
32
  const test = [0.906308, 0.0839613, -0.414194, 0.00103549, 0, 0.980067, 0.198669, -0.000496673, 0.422618, -0.180056, 0.888242, -0.0022206, 0, 0, 0, 'NaN'];
30
33
  try {
31
- // @ts-ignore
32
34
  CSSMatrix.fromArray(test);
33
35
  } catch (err) {
34
36
  expect(err).to.be.instanceOf(TypeError);
@@ -64,7 +66,7 @@ describe('DOMMatrix Class Test', () => {
64
66
 
65
67
  [css1, css2, css3].forEach((c) => {
66
68
  try {
67
- // @ts-ignore
69
+ // @ts-expect-error
68
70
  new CSSMatrix(c);
69
71
  } catch (err) {
70
72
  expect(err).to.be.instanceOf(TypeError);
@@ -77,61 +79,48 @@ describe('DOMMatrix Class Test', () => {
77
79
  const css = new CSSMatrix().rotate(15, 15);
78
80
  const dom = new DOMMatrix().rotate(15, 15);
79
81
 
80
- cy.wrap(new CSSMatrix(css)).as('cc')
81
- .get('@cc').its('is2D').should('equal', css.is2D)
82
- .get('@cc').its('is2D').should('equal', new CSSMatrix(dom).is2D)
83
- .get('@cc').its('isIdentity').should('equal', css.isIdentity)
84
- .get('@cc').its('isIdentity').should('equal', new CSSMatrix(dom).isIdentity);
85
-
86
- cy.wrap(css.toJSON()).as('js')
87
- .get('@js').its('is2D').should('equal', css.is2D)
88
- .get('@js').its('is2D').should('equal', new CSSMatrix(dom).is2D)
89
- .get('@js').its('isIdentity').should('equal', css.isIdentity)
90
- .get('@js').its('isIdentity').should('equal', new CSSMatrix(dom).isIdentity)
82
+ expect(css.is2D).to.equal(dom.is2D)
83
+ expect(css.is2D).to.equal(new CSSMatrix(css).is2D)
84
+ expect(css.isIdentity).to.equal(dom.isIdentity)
85
+ expect(css.isIdentity).to.equal((new CSSMatrix(dom)).isIdentity)
86
+
91
87
  });
92
88
 
93
89
  it('Test specific private methods', () => {
94
- cy.log('CSSMatrix.rotateAxisAngle specific error').then(() => {
95
- try {
96
- // @ts-ignore
97
- new CSSMatrix().rotateAxisAngle('a','true','wombat','05');
98
- } catch (err) {
99
- expect(err).to.be.instanceOf(TypeError);
100
- expect(err).to.have.property('message', 'CSSMatrix: expecting 4 values');
101
- }
102
- });
103
-
104
- cy.log('CSSMatrix.rotate').then(() => {
105
- const d1 = new DOMMatrix().rotate(15);
106
- const m1 = new CSSMatrix().rotate(15);
107
-
108
- cy.get('.bg-primary').then(($el) => {
109
- $el[0].style.transform = m1.toString();
110
- })
111
- .get('.bg-secondary').then(($el) => {
112
- $el[0].style.transform = d1.toString();
113
- })
114
- expect(m1.isIdentity).to.equal(d1.isIdentity);
115
- expect(m1.is2D).to.equal(d1.is2D);
116
-
117
- // for some reason DOMMatrix in
118
- // expect(m1.toFloat32Array()).to.deep.equal(d1.toFloat32Array());
119
- // expect(m1.toFloat64Array()).to.deep.equal(d1.toFloat64Array());
120
- expect(Array.from(m1.toFloat32Array()).map(roundTo4))
121
- .to.deep.equal(Array.from(d1.toFloat32Array()).map(roundTo4));
122
- expect(Array.from(m1.toFloat64Array()).map(roundTo4))
123
- .to.deep.equal(Array.from(d1.toFloat64Array()).map(roundTo4));
124
- });
125
-
126
- cy.log('CSSMatrix.rotate(x:25, y:15)').then(() => {
90
+ try {
91
+ // @ts-ignore
92
+ new CSSMatrix().rotateAxisAngle('a','true','wombat','05');
93
+ } catch (err) {
94
+ expect(err).to.be.instanceOf(TypeError);
95
+ expect(err).to.have.property('message', 'CSSMatrix: expecting 4 values');
96
+ }
97
+
98
+ const d1 = new DOMMatrix().rotate(15);
99
+ const m1 = new CSSMatrix().rotate(15);
100
+
101
+ const cssDiv = container.querySelector('.bg-primary') as HTMLElement;
102
+ const domDiv = container.querySelector('.bg-secondary') as HTMLElement;
103
+
104
+ console.log('Some initial testing');
105
+
106
+ cssDiv.style.transform = m1.toString();
107
+ domDiv.style.transform = d1.toString();
108
+ expect(m1.isIdentity).to.equal(d1.isIdentity);
109
+ expect(m1.is2D).to.equal(d1.is2D);
110
+
111
+ // for some reason DOMMatrix in
112
+ // expect(m1.toFloat32Array()).to.deep.equal(d1.toFloat32Array());
113
+ // expect(m1.toFloat64Array()).to.deep.equal(d1.toFloat64Array());
114
+ expect(Array.from(m1.toFloat32Array()).map(roundTo4))
115
+ .to.deep.equal(Array.from(d1.toFloat32Array()).map(roundTo4));
116
+ expect(Array.from(m1.toFloat64Array()).map(roundTo4))
117
+ .to.deep.equal(Array.from(d1.toFloat64Array()).map(roundTo4));
118
+
119
+ console.log('CSSMatrix.rotate(x:25, y:15)');
127
120
  const d2 = new DOMMatrix().rotate(25,15);
128
121
  const m2 = new CSSMatrix().rotate(25,15);
129
- cy.get('.bg-primary').then(($el) => {
130
- $el[0].style.transform = m2.toString();
131
- })
132
- .get('.bg-secondary').then(($el) => {
133
- $el[0].style.transform = d2.toString();
134
- })
122
+ cssDiv.style.transform = m2.toString();
123
+ domDiv.style.transform = d2.toString();
135
124
 
136
125
  expect(m2.isIdentity).to.equal(d2.isIdentity);
137
126
  expect(m2.is2D).to.equal(d2.is2D);
@@ -143,18 +132,14 @@ describe('DOMMatrix Class Test', () => {
143
132
  .to.deep.equal(Array.from(d2.toFloat32Array()).map(roundTo4));
144
133
  expect(Array.from(m2.toFloat64Array()).map(roundTo4))
145
134
  .to.deep.equal(Array.from(d2.toFloat64Array()).map(roundTo4));
146
- });
147
135
 
148
- cy.log('CSSMatrix.translate(x:150)').then(() => {
136
+
137
+ console.log('CSSMatrix.translate(x:150)');
149
138
  const d3 = new DOMMatrix().translate(150);
150
139
  const m3 = new CSSMatrix().translate(150);
151
140
 
152
- cy.get('.bg-primary').then(($el) => {
153
- $el[0].style.transform = m3.toString();
154
- })
155
- .get('.bg-secondary').then(($el) => {
156
- $el[0].style.transform = d3.toString();
157
- })
141
+ cssDiv.style.transform = m3.toString();
142
+ domDiv.style.transform = d3.toString();
158
143
  expect(m3.isIdentity).to.equal(d3.isIdentity);
159
144
  expect(m3.is2D).to.equal(d3.is2D);
160
145
  // expect(m3.toFloat32Array()).to.deep.equal(d3.toFloat32Array());
@@ -163,18 +148,13 @@ describe('DOMMatrix Class Test', () => {
163
148
  .to.deep.equal(Array.from(d3.toFloat32Array()).map(roundTo4));
164
149
  expect(Array.from(m3.toFloat64Array()).map(roundTo4))
165
150
  .to.deep.equal(Array.from(d3.toFloat64Array()).map(roundTo4));
166
- });
167
151
 
168
- cy.log('CSSMatrix.skew(x:15, y:-20)').then(() => {
152
+ console.log('CSSMatrix.skew(x:15, y:-20)');
169
153
  const d4 = new DOMMatrix('skew(15deg, -20deg)');
170
154
  const m4 = new CSSMatrix().skew(15, -20);
171
- cy.log('In this test we\'re addapting to the output of the native DOMMatrix method since it doesn\'t support the skew() method itself.')
172
- .get('.bg-primary').then(($el) => {
173
- $el[0].style.transform = m4.toString();
174
- })
175
- .get('.bg-secondary').then(($el) => {
176
- $el[0].style.transform = d4.toString();
177
- })
155
+ console.log('In this test we\'re addapting to the output of the native DOMMatrix method since it doesn\'t support the skew() method itself.');
156
+ cssDiv.style.transform = m4.toString();
157
+ domDiv.style.transform = d4.toString();
178
158
  expect(m4.isIdentity).to.equal(d4.isIdentity);
179
159
  expect(m4.is2D).to.equal(d4.is2D);
180
160
  // expect(m4.toFloat32Array()).to.deep.equal(d4.toFloat32Array());
@@ -183,17 +163,13 @@ describe('DOMMatrix Class Test', () => {
183
163
  .to.deep.equal(Array.from(d4.toFloat32Array()).map(roundTo4));
184
164
  expect(Array.from(m4.toFloat64Array()).map(roundTo4))
185
165
  .to.deep.equal(Array.from(d4.toFloat64Array()).map(roundTo4));
186
- });
187
166
 
188
- cy.log('CSSMatrix.scale(x:1.3)').then(() => {
167
+ console.log('CSSMatrix.scale(x:1.3)');
189
168
  const d5 = new DOMMatrix().scale(1.3);
190
169
  const m5 = new CSSMatrix().scale(1.3);
191
- cy.get('.bg-primary').then(($el) => {
192
- $el[0].style.transform = m5.toString();
193
- })
194
- .get('.bg-secondary').then(($el) => {
195
- $el[0].style.transform = d5.toString();
196
- })
170
+
171
+ cssDiv.style.transform = m5.toString();
172
+ domDiv.style.transform = d5.toString();
197
173
  expect(m5.isIdentity).to.equal(d5.isIdentity);
198
174
  expect(m5.is2D).to.equal(d5.is2D);
199
175
  // expect(m5.toFloat32Array()).to.deep.equal(d5.toFloat32Array());
@@ -202,17 +178,12 @@ describe('DOMMatrix Class Test', () => {
202
178
  .to.deep.equal(Array.from(d5.toFloat32Array()).map(roundTo4));
203
179
  expect(Array.from(m5.toFloat64Array()).map(roundTo4))
204
180
  .to.deep.equal(Array.from(d5.toFloat64Array()).map(roundTo4));
205
- });
206
181
 
207
- cy.log('CSSMatrix.scale(x:1.3,y:1.8)').then(() => {
182
+ console.log('CSSMatrix.scale(x:1.3,y:1.8)');
208
183
  const d6 = new DOMMatrix().scale(1.3,1.8);
209
184
  const m6 = new CSSMatrix().scale(1.3,1.8);
210
- cy.get('.bg-primary').then(($el) => {
211
- $el[0].style.transform = m6.toString();
212
- })
213
- .get('.bg-secondary').then(($el) => {
214
- $el[0].style.transform = d6.toString();
215
- })
185
+ cssDiv.style.transform = m6.toString();
186
+ domDiv.style.transform = d6.toString();
216
187
  expect(m6.isIdentity).to.equal(d6.isIdentity);
217
188
  expect(m6.is2D).to.equal(d6.is2D);
218
189
  // expect(m6.toFloat32Array()).to.deep.equal(d6.toFloat32Array());
@@ -221,29 +192,27 @@ describe('DOMMatrix Class Test', () => {
221
192
  .to.deep.equal(Array.from(d6.toFloat32Array()).map(roundTo4));
222
193
  expect(Array.from(m6.toFloat64Array()).map(roundTo4))
223
194
  .to.deep.equal(Array.from(d6.toFloat64Array()).map(roundTo4));
224
- });
225
195
 
226
- cy.log('CSSMatrix.transformPoint').then(() => {
196
+ console.log('CSSMatrix.transformPoint');
227
197
  const p1 = new DOMPoint(15, 20, 35, 1);
228
198
  const p2 = { x: 15, y: 20, z: 35, w: 1};
229
199
  const dp = new DOMMatrix().rotate(15).translate(15, 15);
230
200
  const mp = new CSSMatrix().rotate(15).translate(15, 15);
231
201
 
232
- cy.log('For some reason the native DOMMatrix again falsely claims **is2D** to be true');
202
+ console.log('For some reason the native DOMMatrix again falsely claims **is2D** to be true');
233
203
  expect(mp.isIdentity).to.equal(dp.isIdentity);
234
204
  expect(mp.is2D).to.equal(dp.is2D);
235
205
  expect(mp.toFloat32Array()).to.deep.equal(dp.toFloat32Array());
236
206
  expect(mp.toFloat64Array()).to.deep.equal(dp.toFloat64Array());
237
207
  expect(mp.transformPoint(p1)).to.deep.equal(dp.transformPoint(p1));
238
208
  expect(mp.transformPoint(p2)).to.deep.equal(dp.transformPoint(p2).toJSON());
239
- });
240
209
  });
241
210
 
242
211
  it('Test init a 6 values array', () => {
243
212
  const test = [0.9659, 0.25879, -0.2588, 0.9659, -1.53961, -1.53961] as Matrix;
244
213
  const m1 = new CSSMatrix(test);
245
214
  // const m2 = new CSSMatrix(...test);
246
- const m3 = new CSSMatrix([...test]);
215
+ const m3 = new CSSMatrix(test);
247
216
  const m4 = new DOMMatrix(test);
248
217
 
249
218
  expect(m1.toFloat64Array()).to.deep.equal(m3.toFloat64Array())
@@ -272,7 +241,7 @@ describe('DOMMatrix Class Test', () => {
272
241
  expect(CSSMatrix.fromMatrix(m.toJSON())).to.deep.equal(m);
273
242
 
274
243
  try {
275
- // @ts-ignore
244
+ // @ts-expect-error
276
245
  CSSMatrix.fromString(source);
277
246
  } catch (err) {
278
247
  expect(err).to.be.instanceOf(TypeError);
@@ -306,23 +275,25 @@ describe('DOMMatrix Class Test', () => {
306
275
  const str = testSamples[test];
307
276
  const css = new CSSMatrix(str);
308
277
  const dom = new DOMMatrix(str);
278
+ const cssDiv = container.querySelector('.bg-primary') as HTMLElement;
279
+ const domDiv = container.querySelector('.bg-secondary') as HTMLElement;
309
280
 
310
- cy.get('.bg-primary').then(($el) => {
311
- $el[0].style.transform = css.toString();
312
- });
313
- cy.get('.bg-secondary').then(($el) => {
314
- $el[0].style.transform = dom.toString();
315
- });
281
+ cssDiv.style.transform = css.toString();
282
+ domDiv.style.transform = dom.toString();
316
283
 
317
- cy.log('Due to the nature of the native DOMMatrix RegExp, for consistency reasons we\'re rounding numbers to 6 decimals in this test.')
284
+ console.log('Due to the nature of the native DOMMatrix RegExp, for consistency reasons we\'re rounding numbers to 6 decimals in this test.')
318
285
 
319
286
  expect(Array.from(css.toFloat32Array()).map(roundTo4))
320
287
  .to.deep.equal(Array.from(dom.toFloat32Array()).map(roundTo4));
321
288
 
322
- cy.wrap(css).as('css')
323
- .log('The native `DOMMatrix` is a little weird when it comes to rotateAxisAngle, it falsely claims the identity matrix is NOT `is2D`')
324
- .get('@css').its('isIdentity').should((isIdentity) => expect(isIdentity).to.equal(dom.isIdentity))
325
- .get('@css').its('is2D').should((test === 'rotate3d1' ? 'not.equal' : 'equal'), dom.is2D);
326
- });
289
+ console.log('The native `DOMMatrix` is a little weird when it comes to rotateAxisAngle, it falsely claims the identity matrix is NOT `is2D`');
290
+
291
+ expect(css.isIdentity).to.equal(dom.isIdentity)
292
+ if (test === 'rotate3d1') {
293
+ expect(css.is2D).to.not.equal(dom.is2D)
294
+ } else {
295
+ expect(css.is2D).to.equal(dom.is2D)
296
+ }
297
+ })
327
298
  })
328
299
  });
@@ -1,35 +1,38 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
- <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0">
7
- <title>DOMMatrix Test</title>
8
- <meta name="description" content="DOMMatrix Shim Demo">
9
- <meta name="keywords" content="javascript,svg,svg path,dommatrix,cssmatrix">
10
- <meta name="author" content="thednp">
11
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
12
- <style>
13
- .box {height: 200px;}
14
- #dom, #css {transition: transform 0.5s ease;}
15
- </style>
16
- </head>
17
- <body class="container">
18
- <h1 class="mt-3 mt-md-5"><a class="text-decoration-none" href="https://github.com/thednp/DOMMatrix">DOMMatrix Shim Test</a></h1>
19
-
20
- <div class="row">
21
- <div id="css" class="col-12 col-md-6">
22
- <div class="box bg-primary text-white p-3 my-3 text-center align-self-center rounded">
23
- <b>CSSMatrix</b><br><span class="row"></span>
24
- </div>
25
- </div>
26
- <div id="dom" class="col-12 col-md-6">
27
- <div class="box bg-secondary text-white p-3 my-3 text-center align-self-center rounded">
28
- <b>DOMMatrix</b><br><span class="row"></span>
29
- </div>
30
- </div>
31
- </div>
32
-
33
- </body>
34
-
35
- </html>
1
+ export const getExampleDOM = () => {
2
+ // const CSS = await fetch("https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css").then(r => r.text());
3
+ // This is just a raw example of setting up some DOM
4
+ // that we can interact with. Swap this with your UI
5
+ // framework of choice 😉
6
+ // const div = document.createElement('div');
7
+ const HTML = document.documentElement;
8
+ HTML.innerHTML =
9
+ `<head>
10
+ <meta charset="UTF-8">
11
+ <title>DOMMatrix Testing Page</title>
12
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
13
+ <style>
14
+ .box {height: 200px;}
15
+ #dom, #css {transition: transform 0.5s ease;}
16
+ </style>
17
+ </head>
18
+ <bo<body class="container">
19
+ <h1 class="mt-3 mt-md-5"><a class="text-decoration-none" href="https://github.com/thednp/DOMMatrix">DOMMatrix Shim Test</a></h1>
20
+
21
+ <div class="row">
22
+ <div id="css" class="col-12 col-md-6">
23
+ <div class="box bg-primary text-white p-3 my-3 text-center align-self-center rounded">
24
+ <b>CSSMatrix</b><br><span class="row"></span>
25
+ </div>
26
+ </div>
27
+ <div id="dom" class="col-12 col-md-6">
28
+ <div class="box bg-secondary text-white p-3 my-3 text-center align-self-center rounded">
29
+ <b>DOMMatrix</b><br><span class="row"></span>
30
+ </div>
31
+ </div>
32
+ </div>
33
+
34
+ </body>
35
+ `;
36
+
37
+ return HTML;
38
+ };
File without changes
package/tsconfig.json CHANGED
File without changes
package/vite.config.ts CHANGED
File without changes
@@ -0,0 +1,21 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+
4
+ export default defineConfig({
5
+ test: {
6
+ globals: true,
7
+ coverage: {
8
+ provider: "istanbul",
9
+ reporter: ["html", "text", "lcov"],
10
+ enabled: true,
11
+ include: ["src/**/*.{ts,tsx}"],
12
+ },
13
+ browser: {
14
+ provider: 'preview', // or 'webdriverio'
15
+ enabled: true,
16
+ headless: false,
17
+ name: 'chromium', // browser name is required
18
+ // enableUI: true
19
+ },
20
+ },
21
+ });
@@ -0,0 +1,19 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ coverage: {
7
+ provider: "istanbul",
8
+ reporter: ["html", "text", "lcov"],
9
+ enabled: true,
10
+ include: ["src/**/*.{ts,tsx}"],
11
+ },
12
+ browser: {
13
+ provider: 'playwright', // or 'webdriverio'
14
+ enabled: true,
15
+ headless: true,
16
+ name: 'chromium', // browser name is required
17
+ },
18
+ },
19
+ });
@@ -1,50 +0,0 @@
1
- // sources
2
- // * https://github.com/enketo/enketo-express/blob/master/tools/esbuild-plugin-istanbul.js
3
- 'use strict';
4
- import esbuild from 'esbuild';
5
- import { promises } from 'fs';
6
- import { createInstrumenter } from 'istanbul-lib-instrument';
7
- import { extname, sep } from 'path';
8
- import tsCompile from './tsCompile';
9
-
10
- // import Cypress settings
11
- const sourceFolder = 'src';
12
- const [name] = process.cwd().split(sep).slice(-1);
13
-
14
- const sourceFilter = `${name}${sep}${sourceFolder}`;
15
- const instrumenter = createInstrumenter({
16
- compact: false,
17
- esModules: true,
18
- preserveComments: true,
19
- autoWrap: true,
20
- });
21
-
22
- const createEsbuildIstanbulPlugin = (): esbuild.Plugin => {
23
- return {
24
- name: 'istanbul',
25
- setup(build: esbuild.PluginBuild) {
26
- build.onLoad(
27
- { filter: /\.(ts|tsx)$/ },
28
- async ({ path }: esbuild.OnLoadArgs): Promise<{ contents: string } & Record<string, any>> => {
29
-
30
- if (!path.includes(sourceFilter)) {
31
- // console.log("> compiling typescript %s for output build", path);
32
- const contents = await promises.readFile(path, 'utf8');
33
- return {
34
- contents: ['.ts', '.tsx'].includes(extname(path)) ? tsCompile(path).outputText : contents,
35
- };
36
- }
37
-
38
- // console.log("🧡 instrumenting %s for output coverage", path);
39
- const { outputText, sourceMap } = tsCompile(path);
40
-
41
- return {
42
- contents: instrumenter.instrumentSync(outputText, path, sourceMap),
43
- };
44
- },
45
- );
46
- },
47
- };
48
- };
49
-
50
- export default createEsbuildIstanbulPlugin;
@@ -1,34 +0,0 @@
1
- // compile.ts
2
- import TypeScript from 'typescript';
3
- import { basename } from 'path';
4
- import { RawSourceMap } from 'source-map';
5
- import { readFileSync } from 'fs';
6
-
7
- export default function tsCompile(
8
- path: string,
9
- ops?: Partial<TypeScript.TranspileOptions>,
10
- ): TypeScript.TranspileOutput & { sourceMap: RawSourceMap } {
11
- // Default options -- you could also perform a merge, or use the project tsconfig.json
12
- const options: TypeScript.TranspileOptions = Object.assign(
13
- {
14
- compilerOptions: {
15
- allowJs: true,
16
- esModuleInterop: true,
17
- removeComments: false,
18
- target: 99, // ESNext
19
- allowSyntheticDefaultImports: true,
20
- isolatedModules: true,
21
- noEmitHelpers: true,
22
- sourceMap: true,
23
- } as Partial<TypeScript.CompilerOptions>,
24
- },
25
- ops,
26
- );
27
- const contents = readFileSync(path, { encoding: 'utf8' });
28
- const { outputText, sourceMapText } = TypeScript.transpileModule(contents, options);
29
- const sourceMap: RawSourceMap = JSON.parse(sourceMapText || '');
30
- sourceMap.file = basename(path);
31
- sourceMap.sources = [basename(path)];
32
-
33
- return { outputText, sourceMap, sourceMapText };
34
- }
@@ -1,37 +0,0 @@
1
- /// <reference types="cypress" />
2
- // ***********************************************
3
- // This example commands.ts shows you how to
4
- // create various custom commands and overwrite
5
- // existing commands.
6
- //
7
- // For more comprehensive examples of custom
8
- // commands please read more here:
9
- // https://on.cypress.io/custom-commands
10
- // ***********************************************
11
- //
12
- //
13
- // -- This is a parent command --
14
- // Cypress.Commands.add('login', (email, password) => { ... })
15
- //
16
- //
17
- // -- This is a child command --
18
- // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19
- //
20
- //
21
- // -- This is a dual command --
22
- // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23
- //
24
- //
25
- // -- This will overwrite an existing command --
26
- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27
- //
28
- // declare global {
29
- // namespace Cypress {
30
- // interface Chainable {
31
- // login(email: string, password: string): Chainable<void>
32
- // drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33
- // dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34
- // visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35
- // }
36
- // }
37
- // }
@@ -1,21 +0,0 @@
1
- // ***********************************************************
2
- // This example support/e2e.ts is processed and
3
- // loaded automatically before your test files.
4
- //
5
- // This is a great place to put global configuration and
6
- // behavior that modifies Cypress.
7
- //
8
- // You can change the location of this file or turn off
9
- // automatically serving support files with the
10
- // 'supportFile' configuration option.
11
- //
12
- // You can read more here:
13
- // https://on.cypress.io/configuration
14
- // ***********************************************************
15
-
16
- // Import commands.js using ES2015 syntax:
17
- import "./commands";
18
-
19
- // Alternatively you can use CommonJS syntax:
20
- // require('./commands')
21
- import "@cypress/code-coverage/support";
package/cypress.config.ts DELETED
@@ -1,29 +0,0 @@
1
- import { defineConfig } from "cypress";
2
- import createBundler from "@bahmutov/cypress-esbuild-preprocessor";
3
- import createEsbuildIstanbulPlugin from "./cypress/plugins/esbuild-istanbul";
4
-
5
- async function setupNodeEvents(
6
- on: Cypress.PluginEvents,
7
- config: Cypress.PluginConfigOptions
8
- ): Promise<Cypress.PluginConfigOptions> {
9
- await require("@cypress/code-coverage/task")(on, config);
10
-
11
- on(
12
- "file:preprocessor",
13
- createBundler({
14
- plugins: [createEsbuildIstanbulPlugin()],
15
- })
16
- );
17
-
18
- // Make sure to return the config object as it might have been modified by the plugin.
19
- return config;
20
- }
21
-
22
- export default defineConfig({
23
- e2e: {
24
- specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
25
- supportFile: "cypress/support/e2e.ts",
26
- video: false,
27
- setupNodeEvents,
28
- },
29
- });