mirror of https://github.com/01-edu/public.git
fix(js): replace base64 url trick by temp file
this fix some tests with new version of nodejs
This commit is contained in:
parent
888d46713e
commit
4c65e9e273
|
@ -3,6 +3,7 @@ import { join as joinPath, dirname, extname } from 'path'
|
||||||
import { readFile, writeFile } from 'fs/promises'
|
import { readFile, writeFile } from 'fs/promises'
|
||||||
import { deepStrictEqual } from 'assert'
|
import { deepStrictEqual } from 'assert'
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'url'
|
||||||
|
import { tmpdir } from 'os'
|
||||||
import http from 'http'
|
import http from 'http'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
|
||||||
|
@ -48,14 +49,9 @@ const eq = (a, b) => {
|
||||||
const [solutionPath, name] = process.argv.slice(2)
|
const [solutionPath, name] = process.argv.slice(2)
|
||||||
|
|
||||||
const tools = { eq, fail, wait, randStr, between, upperFirst }
|
const tools = { eq, fail, wait, randStr, between, upperFirst }
|
||||||
const cleanup = (exitCode = 0) => {
|
|
||||||
if (!tools.browser) process.exit(exitCode)
|
|
||||||
tools.server.close()
|
|
||||||
return tools.browser.close().finally(() => process.exit(exitCode))
|
|
||||||
}
|
|
||||||
const fatal = (...args) => {
|
const fatal = (...args) => {
|
||||||
console.error(...args)
|
console.error(...args)
|
||||||
return cleanup(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
solutionPath || fatal('missing solution-path, usage:\nnode test solution-path exercise-name')
|
solutionPath || fatal('missing solution-path, usage:\nnode test solution-path exercise-name')
|
||||||
|
@ -119,7 +115,7 @@ const runInlineTests = async ({ json }) => {
|
||||||
console.log = (...args) => logs.push(args)
|
console.log = (...args) => logs.push(args)
|
||||||
const die = (...args) => {
|
const die = (...args) => {
|
||||||
logs.forEach((logArgs) => console.info(...logArgs))
|
logs.forEach((logArgs) => console.info(...logArgs))
|
||||||
return fatal(...args)
|
fatal(...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
const solution = await loadAndSanitizeSolution()
|
const solution = await loadAndSanitizeSolution()
|
||||||
|
@ -189,12 +185,11 @@ const runTests = async ({ url, path, code }) => {
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.info(`test #${i+1} failed:\n${t.toString()}\n`)
|
console.info(`test #${i+1} failed:\n${t.toString()}\n`)
|
||||||
return fatal(stackFmt(err, url))
|
fatal(stackFmt(err, url))
|
||||||
} finally {
|
} finally {
|
||||||
clearTimeout(timeout)
|
clearTimeout(timeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cleanup(0)
|
|
||||||
console.info(`${name} passed (${tests.length} tests)`)
|
console.info(`${name} passed (${tests.length} tests)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,12 +298,12 @@ const main = async () => {
|
||||||
.replace(inject.trim(), "")
|
.replace(inject.trim(), "")
|
||||||
.trim()}\n${testCode.trim()}\n`
|
.trim()}\n${testCode.trim()}\n`
|
||||||
|
|
||||||
// write to file and read file instead ?
|
const url = `${tmpdir()}/${name}.mjs`
|
||||||
const b64 = Buffer.from(combined).toString("base64")
|
await writeFile(url, combined)
|
||||||
const url = `data:text/javascript;base64,${b64}`
|
|
||||||
return runTests({ path, code, url })
|
return runTests({ path, code, url })
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch(err => {
|
main().then(
|
||||||
fatal(err?.stack || Error('').stack)
|
() => process.exit(0),
|
||||||
})
|
err => fatal(err?.stack || Error('').stack),
|
||||||
|
)
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import { readFile, mkdir } from 'fs/promises'
|
import { readFile } from 'fs/promises'
|
||||||
import { join, resolve } from 'path'
|
|
||||||
import { tmpdir } from 'os'
|
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
import * as cp from 'child_process'
|
import * as cp from 'child_process'
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
We provide you with some content to get started smoothly, check it out!
|
We provide you with some content to get started smoothly, check it out!
|
||||||
|
|
||||||
- Video [Link a CSS stylesheet to your HTML file](https://www.youtube.com/watch?v=e7G-KhaqTjs&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=3)
|
|
||||||
- Video [CSS - Style with type selectors](https://www.youtube.com/watch?v=q0ur7YWBzhs&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=4)
|
- Video [CSS - Style with type selectors](https://www.youtube.com/watch?v=q0ur7YWBzhs&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=4)
|
||||||
- Video [HTML/CSS - Set & style with ID selector](https://www.youtube.com/watch?v=3b3MiY-MR-Y&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=5)
|
- Video [HTML/CSS - Set & style with ID selector](https://www.youtube.com/watch?v=3b3MiY-MR-Y&list=PLHyAJ_GrRtf979iZZ1N3qYMfsPj9PCCrF&index=5)
|
||||||
|
|
||||||
|
@ -56,13 +55,41 @@ Set the `background-color` of the HTML element with the `id` `"block-1"`:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### How to submit
|
||||||
|
|
||||||
|
This exercise must be submited as a JS file, thankfully, javascript allows you to write `CSS` !
|
||||||
|
|
||||||
|
Here is how you would submit the `CSS` sample from above in the editor:
|
||||||
|
|
||||||
|
```js
|
||||||
|
document.documentElement.innerHTML = `
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
|
||||||
|
div {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
#block-1 {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>hello</div>
|
||||||
|
</body>
|
||||||
|
`
|
||||||
|
```
|
||||||
|
|
||||||
|
> Make sure the css is between `<style>` tags and it will be loaded !
|
||||||
|
|
||||||
### Expected output
|
### Expected output
|
||||||
|
|
||||||
This is what you should see in the browser: ![screenshot][8]
|
This is what you should see in the browser: ![screenshot][8]
|
||||||
|
|
||||||
### Notions
|
### Notions
|
||||||
|
|
||||||
- [`link` a CSS file][1]
|
|
||||||
- [CSS basics][7]
|
- [CSS basics][7]
|
||||||
- [ruleset][5]
|
- [ruleset][5]
|
||||||
- [List of different selectors][6]
|
- [List of different selectors][6]
|
||||||
|
@ -71,7 +98,6 @@ This is what you should see in the browser: ![screenshot][8]
|
||||||
- [`id` selector][4]
|
- [`id` selector][4]
|
||||||
|
|
||||||
[0]: https://developer.mozilla.org/en-US/docs/Web/CSS
|
[0]: https://developer.mozilla.org/en-US/docs/Web/CSS
|
||||||
[1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#including_a_stylesheet
|
|
||||||
[2]: https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors
|
[2]: https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors
|
||||||
[3]: https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors
|
[3]: https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors
|
||||||
[4]: https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors
|
[4]: https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors
|
||||||
|
|
Loading…
Reference in New Issue