-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add missing files/code to exercise web vector examples in CI
- Loading branch information
Showing
8 changed files
with
216 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
dist | ||
**/*.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"root": true, | ||
"env": { | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"plugin:import/recommended", | ||
"plugin:prettier/recommended", | ||
"plugin:node/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 12, | ||
"project": "./tsconfig.json" | ||
}, | ||
"plugins": ["@typescript-eslint"], | ||
"rules": { | ||
"semi": ["error", "always"], | ||
"import/no-extraneous-dependencies": ["error", {}], | ||
"node/no-unsupported-features/es-syntax": "off", | ||
"node/no-missing-import": [ | ||
"error", | ||
{ | ||
"tryExtensions": [".js", ".ts", ".json", ".node"] | ||
} | ||
], | ||
"prettier/prettier": "error", | ||
"block-scoped-var": "error", | ||
"eqeqeq": "error", | ||
"no-var": "error", | ||
"prefer-const": "error", | ||
"eol-last": "error", | ||
"prefer-arrow-callback": "error", | ||
"no-trailing-spaces": "error", | ||
"quotes": ["warn", "single", {"avoidEscape": true}], | ||
"no-restricted-properties": [ | ||
"error", | ||
{ | ||
"object": "describe", | ||
"property": "only" | ||
}, | ||
{ | ||
"object": "it", | ||
"property": "only" | ||
} | ||
], | ||
// async without await is often an error and in other uses it obfuscates | ||
// the intent of the developer. Functions are async when they want to await. | ||
"require-await": "error", | ||
"import/no-duplicates": "error" | ||
}, | ||
"settings": { | ||
"import/resolver": { | ||
"node": { | ||
"extensions": [".js", ".jsx", ".ts", ".tsx"] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"bracketSpacing": false, | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"arrowParens": "avoid", | ||
"printWidth": 120 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2021", | ||
"module": "commonjs", | ||
"lib": [ | ||
"es2021", | ||
], | ||
"declaration": true, | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"noImplicitThis": true, | ||
"alwaysStrict": true, | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": false, | ||
"inlineSourceMap": true, | ||
"inlineSources": true, | ||
"experimentalDecorators": true, | ||
"strictPropertyInitialization": false, | ||
"typeRoots": [ | ||
"./node_modules/@types" | ||
], | ||
"outDir": "./dist" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return */ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-nocheck | ||
|
||
const JSDOM = require('jsdom'); | ||
|
||
const defaultHtml = '<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>'; | ||
|
||
export function initJSDom(html = defaultHtml, options = {}) { | ||
// Idempotency | ||
if ( | ||
global.navigator && | ||
global.navigator.userAgent && | ||
global.navigator.userAgent.includes('Node.js') && | ||
global.document && | ||
typeof global.document.destroy === 'function' | ||
) { | ||
return global.document.destroy; | ||
} | ||
|
||
if (!('url' in options)) { | ||
Object.assign(options, {url: 'http://localhost:3000'}); | ||
} | ||
|
||
// enable pretendToBeVisual by default since react needs | ||
// window.requestAnimationFrame, see https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser | ||
if (!('pretendToBeVisual' in options)) { | ||
Object.assign(options, {pretendToBeVisual: true}); | ||
} | ||
|
||
const jsdom = new JSDOM.JSDOM(html, options); | ||
const {window} = jsdom; | ||
const {document} = window; | ||
|
||
// generate our list of keys by enumerating document.window - this list may vary | ||
// based on the jsdom version. filter out internal methods as well as anything | ||
// that node already defines | ||
|
||
const KEYS = []; | ||
|
||
if (KEYS.length === 0) { | ||
KEYS.push(...Object.getOwnPropertyNames(window).filter(k => !k.startsWith('_') && !(k in global))); | ||
// going to add our jsdom instance, see below | ||
KEYS.push('$jsdom'); | ||
} | ||
KEYS.forEach(key => (global[key] = window[key])); | ||
|
||
// setup document / window / window.console | ||
global.document = document; | ||
global.window = window; | ||
window.console = global.console; | ||
|
||
// add access to our jsdom instance | ||
global.$jsdom = jsdom; | ||
|
||
const cleanup = () => KEYS.forEach(key => delete global[key]); | ||
|
||
document.destroy = cleanup; | ||
|
||
return cleanup; | ||
} |