Skip to content

Update dependencies #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .eslintrc.cjs

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
dist/*
stats.html
.vscode
node_modules
/extensions
7 changes: 7 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
singleQuote: true,
jsxSingleQuote: true,
trailingComma: 'none',
semi: false,
printWidth: 100
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
}
12 changes: 10 additions & 2 deletions FixJSDOMEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ import { TestEnvironment } from 'jest-environment-jsdom'

class FixJSDOMEnvironment extends TestEnvironment {
constructor(...args) {
super(...args);
super(...args)

this.dom.virtualConsole.removeAllListeners('jsdomError')
this.dom.virtualConsole.on('jsdomError', (error) => {
if (error.message.startsWith('Could not parse CSS stylesheet')) {
return
}
context.console.error(error)
})

// FIXME https://github.com/jsdom/jsdom/issues/3363
this.global.structuredClone = structuredClone;
this.global.structuredClone = structuredClone
}
}

Expand Down
133 changes: 69 additions & 64 deletions browserMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,33 @@ import { performance } from 'perf_hooks'
import { fetch as fetchPolyfill } from 'whatwg-fetch'

Object.defineProperty(document, 'queryCommandSupported', {
value: jest.fn().mockImplementation(() => true),
});
value: jest.fn().mockImplementation(() => true)
})

window.process = undefined

Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
dispatchEvent: jest.fn()
}))
})

Object.defineProperty(window, 'fetch', {
value: jest.fn(async (url, options) => {
if (url.startsWith('file:')) {
const content = await fs.readFile(new URL(url).pathname)
return {
json: async () => JSON.stringify(JSON.parse(content.toString())),
arrayBuffer: async () => content.buffer.slice(content.byteOffset, content.byteOffset + content.byteLength),
arrayBuffer: async () =>
content.buffer.slice(content.byteOffset, content.byteOffset + content.byteLength),
status: 200
}
} else {
Expand All @@ -47,8 +48,8 @@ Object.defineProperty(window, 'Worker', {
value: class Worker {
constructor(stringUrl) {}
postMessage(msg) {}
terminate () {}
removeEventListener () {}
terminate() {}
removeEventListener() {}
}
})

Expand All @@ -62,77 +63,77 @@ Object.defineProperty(window, 'ResizeObserver', {
// These 2 classes come from https://gist.github.com/Yaffle/5458286
Object.defineProperty(window, 'TextEncoder', {
value: class TextEncoder {
encode (string) {
var octets = [];
var length = string.length;
var i = 0;
encode(string) {
var octets = []
var length = string.length
var i = 0
while (i < length) {
var codePoint = string.codePointAt(i);
var c = 0;
var bits = 0;
if (codePoint <= 0x0000007F) {
c = 0;
bits = 0x00;
} else if (codePoint <= 0x000007FF) {
c = 6;
bits = 0xC0;
} else if (codePoint <= 0x0000FFFF) {
c = 12;
bits = 0xE0;
} else if (codePoint <= 0x001FFFFF) {
c = 18;
bits = 0xF0;
var codePoint = string.codePointAt(i)
var c = 0
var bits = 0
if (codePoint <= 0x0000007f) {
c = 0
bits = 0x00
} else if (codePoint <= 0x000007ff) {
c = 6
bits = 0xc0
} else if (codePoint <= 0x0000ffff) {
c = 12
bits = 0xe0
} else if (codePoint <= 0x001fffff) {
c = 18
bits = 0xf0
}
octets.push(bits | (codePoint >> c));
c -= 6;
octets.push(bits | (codePoint >> c))
c -= 6
while (c >= 0) {
octets.push(0x80 | ((codePoint >> c) & 0x3F));
c -= 6;
octets.push(0x80 | ((codePoint >> c) & 0x3f))
c -= 6
}
i += codePoint >= 0x10000 ? 2 : 1;
i += codePoint >= 0x10000 ? 2 : 1
}
return Uint8Array.from(octets);
return Uint8Array.from(octets)
}
}
})
Object.defineProperty(window, 'TextDecoder', {
value: class TextDecoder {
decode (octets) {
decode(octets) {
if (octets == null) {
return ''
}
var string = "";
var i = 0;
var string = ''
var i = 0
while (i < octets.length) {
var octet = octets[i];
var bytesNeeded = 0;
var codePoint = 0;
if (octet <= 0x7F) {
bytesNeeded = 0;
codePoint = octet & 0xFF;
} else if (octet <= 0xDF) {
bytesNeeded = 1;
codePoint = octet & 0x1F;
} else if (octet <= 0xEF) {
bytesNeeded = 2;
codePoint = octet & 0x0F;
} else if (octet <= 0xF4) {
bytesNeeded = 3;
codePoint = octet & 0x07;
var octet = octets[i]
var bytesNeeded = 0
var codePoint = 0
if (octet <= 0x7f) {
bytesNeeded = 0
codePoint = octet & 0xff
} else if (octet <= 0xdf) {
bytesNeeded = 1
codePoint = octet & 0x1f
} else if (octet <= 0xef) {
bytesNeeded = 2
codePoint = octet & 0x0f
} else if (octet <= 0xf4) {
bytesNeeded = 3
codePoint = octet & 0x07
}
if (octets.length - i - bytesNeeded > 0) {
var k = 0;
var k = 0
while (k < bytesNeeded) {
octet = octets[i + k + 1];
codePoint = (codePoint << 6) | (octet & 0x3F);
k += 1;
octet = octets[i + k + 1]
codePoint = (codePoint << 6) | (octet & 0x3f)
k += 1
}
} else {
codePoint = 0xFFFD;
bytesNeeded = octets.length - i;
codePoint = 0xfffd
bytesNeeded = octets.length - i
}
string += String.fromCodePoint(codePoint);
i += bytesNeeded + 1;
string += String.fromCodePoint(codePoint)
i += bytesNeeded + 1
}
return string
}
Expand All @@ -145,15 +146,19 @@ Object.defineProperty(window, 'Buffer', {

// Force override performance, for some reason the implementation is empty otherwise
let _performance = performance
// remove nodeTiming because otherwise VSCode refuse to detect the env as a browser env, and it also fails to detect a node env (no `process`) so it generates an error
performance.nodeTiming = undefined
Object.defineProperty(global, 'performance', {
get () { return _performance },
set (v) {
get() {
return _performance
},
set(v) {
// ignore
}
})

global.CSS = {
escape: v => v
escape: (v) => v
}

Element.prototype.scrollIntoView = jest.fn();
Element.prototype.scrollIntoView = jest.fn()
4 changes: 2 additions & 2 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
extends: ['@codingame/commitlint-config-codingame']
};
extends: ['@codingame/commitlint-config-codingame']
}
12 changes: 12 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
import globals from 'globals'

export default tseslint.config(eslint.configs.recommended, tseslint.configs.recommended, {
rules: { '@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }] },
languageOptions: {
globals: {
...globals.browser
}
}
})
Loading
Loading