Skip to content

Commit

Permalink
Format with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
yandeu committed Mar 10, 2024
1 parent a6e230d commit 00c32e3
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 57 deletions.
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.html
*.json
*.md
*.min.js
34 changes: 16 additions & 18 deletions scripts/browserTest/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,54 @@ const args = process.argv.splice(2)
const serve = args.includes('serve')
const collectCoverage = args.includes('--coverage') && !serve


const ERROR_CODES = {
TEST_FAILED: 2,
HAS_ERROR: 3
}

let hasError = false

const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
const sleep = ms => new Promise(r => setTimeout(r, ms))

const server = createServer(requestListener({ serve, collectCoverage }))
server.closeAsync = () => /** @type {Promise<void>} */(new Promise(resolve => server.close(() => resolve())))
server.closeAsync = () => /** @type {Promise<void>} */ (new Promise(resolve => server.close(() => resolve())))

/**
* @param {{fileName:string, browser:puppeteer.Browser}} param0
* @param {{fileName:string, browser:puppeteer.Browser}} param0
*/
const main = async ({ fileName, browser }) => {
console.log(`> ${fileName}`)

const page = await browser.newPage()
await page.setRequestInterception(true);
await page.setRequestInterception(true)

// Enable both JavaScript and CSS coverage
if (collectCoverage) await page.coverage.startJSCoverage()

/** @type {Array<puppeteer.HTTPRequest>} */
const requests = [];
const requests = []

// Blocks all window.location.href requests
page.on('request', async request => {
let isNavRequest = request.isNavigationRequest() && request.frame() === page.mainFrame();
let isNavRequest = request.isNavigationRequest() && request.frame() === page.mainFrame()
if (!isNavRequest) {
request.continue();
return;
request.continue()
return
}

requests.push(request);
requests.push(request)
if (requests.length == 1) {
request.continue();
return;
request.continue()
return
}

request.abort('aborted');
request.abort('aborted')

const url = requests[requests.length - 1].url()
await page.evaluate((url) => {
window.__gotohref__ = url;
}, url);

});
await page.evaluate(url => {
window.__gotohref__ = url
}, url)
})

// Navigate to page
let url = `http://localhost:8080/${fileName.replace(/^\+/, '')}`
Expand Down
2 changes: 1 addition & 1 deletion scripts/browserTest/requestListener.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const requestListener = ({ serve, collectCoverage }) => {
return res.writeHead(200, { 'Content-Type': contentType }).end(file)
}
} catch (err) {
if(!err.message.endsWith(".ico'")) {
if (!err.message.endsWith(".ico'")) {
console.log('Error:', err.message)
}
return res.writeHead(500).end()
Expand Down
20 changes: 14 additions & 6 deletions test/nodejs/component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@ test('should render without errors', async () => {
}

didMount() {
setTimeout(() => {
this.state = { ...this.state, number: (this.state.number += 0.1) }
this.update()
}, Math.random() * 1000 + 200)
setTimeout(
() => {
this.state = { ...this.state, number: (this.state.number += 0.1) }
this.update()
},
Math.random() * 1000 + 200
)
}

render() {
Expand Down Expand Up @@ -161,7 +164,7 @@ test('should render without errors', async () => {
constructor(props: any) {
super(props)
this.id = 'update-test'
this.state = ({ name: 'default', description: 'default' })
this.state = { name: 'default', description: 'default' }
}

didMount() {
Expand Down Expand Up @@ -190,7 +193,12 @@ test('should render without errors', async () => {

render() {
return (
<div><ul><li>{this.state.name}</li><li>{this.state.description}</li></ul></div>
<div>
<ul>
<li>{this.state.name}</li>
<li>{this.state.description}</li>
</ul>
</div>
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/nodejs/components/link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ test('should render Link Component ("hover" and back)', async () => {
}, 100)
}}
prefetch="hover"
href="http://geckos.io/">
href="http://geckos.io/"
>
Link to geckos.io
</Link>
<Link back href="http://enable3d.io/">
Expand Down
6 changes: 4 additions & 2 deletions test/nodejs/ref.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ test('should render without errors', async () => {
<div
ref={(node: HTMLDivElement) => {
ref1 = nodeToString(node)
}}>
}}
>
<p
id="text-id"
ref={(node: HTMLParagraphElement) => {
ref2 = nodeToString(node)
}}>
}}
>
some text
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion test/nodejs/router.ssr.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test('should render without errors', () => {
}
}

let Hello = (p:any)=> (<div>hello {p.route.params.name}</div>)
let Hello = (p: any) => <div>hello {p.route.params.name}</div>

class App extends Component {
render() {
Expand Down
2 changes: 1 addition & 1 deletion test/nodejs/router.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test('should render without errors', async () => {
}
}

let Hello = (p:any)=> (<div>hello {p.route.params.name}</div>)
let Hello = (p: any) => <div>hello {p.route.params.name}</div>

class App extends Component {
didMount() {
Expand Down
8 changes: 1 addition & 7 deletions test/nodejs/suspense.ssr.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ test('should render without errors', async () => {
}

const Comments: FC<{ comments?: string[] }> = ({ comments }) => {
return (
<ul>
{comments?.map(c => (
<li>{c}</li>
))}
</ul>
)
return <ul>{comments?.map(c => <li>{c}</li>)}</ul>
}

const Loading = () => <div>loading...</div>
Expand Down
8 changes: 1 addition & 7 deletions test/nodejs/suspense.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ test('should render without errors', async () => {
}

const Comments: FC<{ comments?: string[] }> = ({ comments }) => {
return (
<ul>
{comments?.map(c => (
<li>{c}</li>
))}
</ul>
)
return <ul>{comments?.map(c => <li>{c}</li>)}</ul>
}

const Loading = () => <div>loading...</div>
Expand Down
25 changes: 12 additions & 13 deletions test/scripts.mjs
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
// @ts-check

import { readFile, readdir, writeFile } from "fs/promises"
import { resolve } from "path"
import { readFile, readdir, writeFile } from 'fs/promises'
import { resolve } from 'path'

const args = process.argv.splice(2)
const arg0 = args[0]

async function* getFiles(dir) {
const dirents = await readdir(dir, { withFileTypes: true });
const dirents = await readdir(dir, { withFileTypes: true })
for (const dirent of dirents) {
const res = resolve(dir, dirent.name);
const res = resolve(dir, dirent.name)
if (dirent.isDirectory()) {
yield* getFiles(res);
yield* getFiles(res)
} else {
yield res;
yield res
}
}
}

if (arg0 === "add-jest-environment") {
const str = "/**\n* @jest-environment node\n*/\n\n"
if (arg0 === 'add-jest-environment') {
const str = '/**\n* @jest-environment node\n*/\n\n'

for await (const f of getFiles("test")) {
for await (const f of getFiles('test')) {
if (/ssr\.test\.js/.test(f) || /e2e\/core\.test\.js/.test(f)) {
const file = await readFile(f, { encoding: "utf-8" })
await writeFile(f, str + file, { encoding: "utf-8" })
const file = await readFile(f, { encoding: 'utf-8' })
await writeFile(f, str + file, { encoding: 'utf-8' })
}
}

}
}

0 comments on commit 00c32e3

Please sign in to comment.