Skip to content

Instantly share code, notes, and snippets.

@jimmont
Last active September 15, 2021 19:55
Show Gist options
  • Save jimmont/715d1f7584409f4c96a009573aa7baca to your computer and use it in GitHub Desktop.
Save jimmont/715d1f7584409f4c96a009573aa7baca to your computer and use it in GitHub Desktop.
async Deno.test() tests
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