Skip to content

Commit c47f2d1

Browse files
committed
Merge branch 'master' into fix_build_settings
2 parents 7b6250a + 5851cc8 commit c47f2d1

File tree

9 files changed

+552
-476
lines changed

9 files changed

+552
-476
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"devDependencies": {
2828
"@rollup/plugin-node-resolve": "^7.0.0",
29+
"@kamiazya/jest-dynamic": "^0.0.1",
2930
"@types/node": "^13.1.6",
3031
"jest-snapshot": "^25.4.0",
3132
"prettier": "^1.19.1",

src/__test__/__snapshots__/index.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`public api toBeValidDotAndMatchSnapshot 1`] = `"digraph g { a -> b; }"`;
3+
exports[`public api toBeValidDotAndMatchSnapshot 1`] = `digraph g { a -> b; }`;
44

55
exports[`public api toMatchDotJsonSnapshot 1`] = `
66
Object {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`toBeValidDotAndMatchSnapshot test matcher works 1`] = `"digraph g { a -> b; }"`;
3+
exports[`toBeValidDotAndMatchSnapshot test matcher works 1`] = `digraph g { a -> b; }`;

src/__test__/index.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import { skipOn } from '@kamiazya/jest-dynamic';
12
import '../index';
2-
describe('public api', () => {
3-
const runOnWindows = process.platform === 'win32';
43

5-
const dot = 'digraph g { a -> b; }';
4+
const skipOnWindows = skipOn('win32');
65

6+
describe('public api', () => {
7+
const dot = 'digraph g { a -> b; }';
78
// Skip test on windows
89
// NOTE: Not support output json format on Graphviz windows statable now.
9-
(runOnWindows ? test.skip : test)('toMatchDotJsonSnapshot', () => {
10+
skipOnWindows.test('toMatchDotJsonSnapshot', () => {
1011
expect(dot).toMatchDotJsonSnapshot();
1112
});
1213

src/__test__/to-match-dot-json-snapshot.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { skipOn } from '@kamiazya/jest-dynamic';
12
import '../to-match-dot-json-snapshot';
23

3-
const runOnWindows = process.platform === 'win32';
4+
const skipOnWindows = skipOn('win32');
5+
46
// Skip test on windows
57
// NOTE: Not support output json format on Graphviz windows statable now.
6-
(runOnWindows ? describe.skip : describe)('toMatchDotJsonSnapshot test', () => {
8+
skipOnWindows.describe('toMatchDotJsonSnapshot test', () => {
79
test('matcher works', () => {
810
const dot = 'digraph g { a -> b; }';
911
expect(dot).toMatchDotJsonSnapshot();

src/lib/__test__/dot-adapter.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { skipOn } from '@kamiazya/jest-dynamic';
12
import { checkValidDot, dotJsonStdin } from '../dot-adapter';
23

4+
const skipOnWindows = skipOn('win32');
5+
36
describe('checkValidDot test', () => {
47
test('valid dot', () => {
58
expect(() => {
@@ -16,10 +19,9 @@ describe('checkValidDot test', () => {
1619
});
1720
});
1821

19-
const runOnWindows = process.platform === 'win32';
2022
// Skip test on windows
2123
// NOTE: Not support output json format on Graphviz windows statable now.
22-
(runOnWindows ? describe.skip : describe)('dotJsonStdin test', () => {
24+
skipOnWindows.describe('dotJsonStdin test', () => {
2325
test('valid dot', () => {
2426
const dot = 'digraph g { a -> b; }';
2527
const result = dotJsonStdin(dot);

src/serializer.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const raw = Symbol();
2+
3+
interface IWrapper {
4+
[raw]: string;
5+
}
6+
7+
function test(something: any): something is IWrapper {
8+
return something && typeof something[raw] === 'string';
9+
}
10+
11+
function print(wrapper: IWrapper): string {
12+
return wrapper[raw];
13+
}
14+
15+
export function wrap(value: string): IWrapper {
16+
return { [raw]: value };
17+
}
18+
19+
export const SnapshotSerializer: jest.SnapshotSerializerPlugin = {
20+
test,
21+
print,
22+
};
23+
24+
expect.addSnapshotSerializer(SnapshotSerializer);

src/to-be-valid-dot-and-match-snapshot.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { toMatchSnapshot } from 'jest-snapshot';
22
import { isValidDot } from './lib/is-valid-dot';
3+
import { wrap } from './serializer';
34

45
export function toBeValidDotAndMatchSnapshotMatcher(this: any, dot: string): jest.CustomMatcherResult {
56
const result = isValidDot(dot);
67
if (result.pass) {
7-
return toMatchSnapshot.call(this, dot);
8+
return toMatchSnapshot.call(this, wrap(dot));
89
}
910
return result;
1011
}

0 commit comments

Comments
 (0)