Skip to content

Commit 48041ac

Browse files
Merge pull request #18 from CodinGame/add-tests
Add tests
2 parents a153846 + fd7d807 commit 48041ac

14 files changed

+16133
-7426
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module.exports = {
22
env: {
33
browser: true,
4-
es6: true
4+
es6: true,
5+
jest: true
56
},
67
extends: [
78
'standard'

babel.test.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
plugins: [
3+
["@babel/plugin-transform-modules-commonjs", {
4+
importInterop: 'babel'
5+
}]
6+
],
7+
presets: [
8+
"@babel/preset-env",
9+
"@babel/preset-typescript"
10+
]
11+
};

browserMock.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const fs = require('fs/promises')
2+
3+
Object.defineProperty(document, 'queryCommandSupported', {
4+
value: jest.fn().mockImplementation(() => true),
5+
});
6+
7+
Object.defineProperty(window, 'matchMedia', {
8+
writable: true,
9+
value: jest.fn().mockImplementation(query => ({
10+
matches: false,
11+
media: query,
12+
onchange: null,
13+
addListener: jest.fn(), // Deprecated
14+
removeListener: jest.fn(), // Deprecated
15+
addEventListener: jest.fn(),
16+
removeEventListener: jest.fn(),
17+
dispatchEvent: jest.fn(),
18+
})),
19+
});
20+
21+
Object.defineProperty(window, 'fetch', {
22+
value: jest.fn(async (path) => {
23+
24+
const content = await fs.readFile(path)
25+
return {
26+
json: async () => JSON.stringify(JSON.parse(content.toString())),
27+
arrayBuffer: async () => content.buffer.slice(content.byteOffset, content.byteOffset + content.byteLength)
28+
}
29+
})
30+
})
31+
32+
Object.defineProperty(URL, 'createObjectURL', {
33+
value: jest.fn((blob) => {
34+
35+
return null
36+
})
37+
})
38+
39+
Object.defineProperty(window, 'Worker', {
40+
value: class Worker {
41+
constructor(stringUrl) {}
42+
postMessage(msg) {}
43+
terminate () {}
44+
}
45+
})
46+
47+
Object.defineProperty(window, 'ResizeObserver', {
48+
value: class ResizeObserver {
49+
constructor(stringUrl) {}
50+
observe() {}
51+
}
52+
})

jest/cssTransform.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
// This is a custom Jest transformer turning style imports into empty objects.
4+
// http://facebook.github.io/jest/docs/en/webpack.html
5+
6+
module.exports = {
7+
process() {
8+
return 'module.exports = {};';
9+
},
10+
getCacheKey() {
11+
// The output is always the same.
12+
return 'cssTransform';
13+
},
14+
};

jest/fileTransform.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
process(src, filename) {
3+
const assetFilename = JSON.stringify(filename);
4+
5+
return `module.exports = ${assetFilename};`;
6+
},
7+
};

0 commit comments

Comments
 (0)