Last active
August 6, 2024 12:28
-
-
Save jimmont/715d1f7584409f4c96a009573aa7baca to your computer and use it in GitHub Desktop.
async Deno.test() tests
This file contains hidden or 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
/* | |
REPLACED BY astral version at https://gist.github.com/jimmont/d70845b0fc7e673b1676fb08dd70d025 | |
*/ | |
import puppeteer from 'https://deno.land/x/puppeteer/mod.ts'; | |
import { assert } from 'https://deno.land/std/testing/asserts.ts'; | |
/* | |
related: | |
async runTests() | |
https://github.com/denoland/deno/issues/10941 | |
https://github.com/denoland/deno_std/issues/162 | |
discussion of testing API | |
https://github.com/denoland/deno/discussions/10771 | |
more | |
https://deno.land/manual/testing | |
https://deno.land/std/testing | |
* */ | |
const browser = await puppeteer.launch({ | |
headless: false, | |
devtools: true, | |
slowMo: 250, | |
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', | |
// args: ['--no-sandbox'] | |
}); | |
const [page] = await browser.pages(); | |
const url = 'http://localhost:8000/'; | |
await page.goto(url).catch(error=>{ | |
console.error(`can't open ${ url } "${error.message}"`); | |
Deno.exit(1); | |
}); | |
const result = await page.evaluate(()=>{ | |
return {url: location.href}; | |
}); | |
console.log('>Deno.test() is next'); | |
let n = 0; | |
Deno.test(`test${ n++ }`, async ()=>{ | |
assert(result.url, 'has a url'); | |
console.log(`<Deno.test() ran ${ n }`); | |
}); | |
Deno.test(`test${ n++ }`, ()=>{ | |
assert(result.url, 'has a url'); | |
console.log(`<Deno.test() ran ${ n }`); | |
}); | |
Deno.test(`test${ n++ }`, async ()=>{ | |
assert(result.url, 'has a url'); | |
console.log(`<Deno.test() ran ${ n }`); | |
}); | |
Deno.test(`test${ n++ }`, async ()=>{ | |
assert(result.url, 'has a url'); | |
console.log(`<Deno.test() ran ${ n }`); | |
}); | |
// runs them all again a second time when not wrapped in outer async function | |
await Deno[Deno.internal].runTests(); | |
await browser.close(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
replaced by astral version at https://gist.github.com/jimmont/d70845b0fc7e673b1676fb08dd70d025