Skip to content

Commit 11af242

Browse files
committed
wip
1 parent 6c1b995 commit 11af242

File tree

3 files changed

+54
-63
lines changed

3 files changed

+54
-63
lines changed

packages/vue/tests/injectors/modifyScriptSetup.test.js

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,10 @@
11
import {describe, expect, test} from '@jest/globals';
2+
import {makeBlock, setupCodeMatcher} from '../shared.js';
23
import injector from '../../injectors/modifyScriptSetup.js';
34

4-
function makeBlock(code) {
5-
return {
6-
content: code,
7-
loc: {start: {offset: 0}, end: {offset: code.length}}
8-
}
9-
}
10-
11-
expect.extend({
12-
toMatchCode(received, expected) {
13-
const normalize = str => str.replace(/\s+/g, ' ').trim();
14-
const normalizedReceived = normalize(received);
15-
const normalizedExpected = normalize(expected);
16-
17-
const pass = normalizedReceived === normalizedExpected;
18-
19-
if (pass) {
20-
return {
21-
message: () =>
22-
`Expected code not to match:\n` +
23-
`Expected: ${this.utils.printExpected(normalizedExpected)}\n` +
24-
`Received: ${this.utils.printReceived(normalizedReceived)}`,
25-
pass: true
26-
};
27-
} else {
28-
return {
29-
message: () =>
30-
`Expected code to match:\n` +
31-
`Expected: ${this.utils.printExpected(normalizedExpected)}\n` +
32-
`Received: ${this.utils.printReceived(normalizedReceived)}`,
33-
pass: false
34-
};
35-
}
36-
}
37-
});
5+
6+
// Setup the custom matcher
7+
setupCodeMatcher();
388

399
describe('injector', () => {
4010
test('handles code with no useFusion import', () => {

packages/vue/tests/injectors/optionsWithSetup.test.js

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
11
import {describe, expect, test} from '@jest/globals';
2+
import {makeBlock, setupCodeMatcher} from '../shared.js';
23
import optionsWithSetup from '../../injectors/optionsWithSetup.js';
34

4-
function makeBlock(code) {
5-
return {
6-
content: code,
7-
loc: {start: {offset: 0}, end: {offset: code.length}}
8-
};
9-
}
10-
11-
expect.extend({
12-
toMatchCode(received, expected) {
13-
const normalize = str => str.replace(/\s+/g, ' ').trim();
14-
const normalizedReceived = normalize(received);
15-
const normalizedExpected = normalize(expected);
16-
const pass = normalizedReceived === normalizedExpected;
17-
18-
if (pass) {
19-
return {
20-
message: () =>
21-
`Expected code not to match:\nExpected: ${this.utils.printExpected(normalizedExpected)}\nReceived: ${this.utils.printReceived(normalizedReceived)}`,
22-
pass: true
23-
};
24-
} else {
25-
return {
26-
message: () =>
27-
`Expected code to match:\nExpected: ${this.utils.printExpected(normalizedExpected)}\nReceived: ${this.utils.printReceived(normalizedReceived)}`,
28-
pass: false
29-
};
30-
}
31-
}
32-
});
5+
6+
// Setup the custom matcher
7+
setupCodeMatcher();
338

349
describe('optionsWithSetup', () => {
3510
test('handles code with no useFusion call', () => {

packages/vue/tests/shared.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// test-helpers.js
2+
import {expect} from '@jest/globals';
3+
4+
/**
5+
* Creates a code block object with location information
6+
* @param {string} code - The source code
7+
* @returns {Object} Block object with content and location info
8+
*/
9+
export function makeBlock(code) {
10+
return {
11+
content: code,
12+
loc: {start: {offset: 0}, end: {offset: code.length}}
13+
};
14+
}
15+
16+
/**
17+
* Custom Jest matcher for comparing code strings while ignoring whitespace differences
18+
*/
19+
export function setupCodeMatcher() {
20+
expect.extend({
21+
toMatchCode(received, expected) {
22+
const normalize = str => str.replace(/\s+/g, ' ').trim();
23+
const normalizedReceived = normalize(received);
24+
const normalizedExpected = normalize(expected);
25+
const pass = normalizedReceived === normalizedExpected;
26+
27+
if (pass) {
28+
return {
29+
message: () =>
30+
`Expected code not to match:\n` +
31+
`Expected: ${this.utils.printExpected(normalizedExpected)}\n` +
32+
`Received: ${this.utils.printReceived(normalizedReceived)}`,
33+
pass: true
34+
};
35+
} else {
36+
return {
37+
message: () =>
38+
`Expected code to match:\n` +
39+
`Expected: ${this.utils.printExpected(normalizedExpected)}\n` +
40+
`Received: ${this.utils.printReceived(normalizedReceived)}`,
41+
pass: false
42+
};
43+
}
44+
}
45+
});
46+
}

0 commit comments

Comments
 (0)