Skip to content

Commit

Permalink
meta: fix missing EOL and end of e2e test templates (#3484)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Feb 17, 2022
1 parent f4f1b81 commit c2692e4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
30 changes: 23 additions & 7 deletions e2e/generate-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@
/* eslint-disable no-console, import/no-extraneous-dependencies */
import prompts from 'prompts'
import fs from 'node:fs/promises'
import dedent from 'dedent'

/**
* Utility function that strips indentation from multi-line strings.
* Inspired from https://github.com/dmnd/dedent.
*/
function dedent (strings, ...parts) {
const nonSpacingChar = /\S/m.exec(strings[0])
if (nonSpacingChar == null) return ''

const indent = nonSpacingChar.index - strings[0].lastIndexOf('\n', nonSpacingChar.index) - 1
const dedentEachLine = str => str.split('\n').map((line, i) => line.slice(i && indent)).join('\n')
let returnLines = dedentEachLine(strings[0].slice(nonSpacingChar.index), indent)
for (let i = 1; i < strings.length; i++) {
returnLines += String(parts[i - 1]) + dedentEachLine(strings[i], indent)
}
return returnLines
}

const packageNames = await fs.readdir(new URL('../packages/@uppy', import.meta.url))
const unwantedPackages = ['core', 'companion', 'redux-dev-tools', 'utils']
Expand Down Expand Up @@ -54,14 +70,14 @@ const html = dedent`
const appUrl = new URL(`clients/${name}/app.js`, import.meta.url)
// dedent is acting weird for this one but this formatting fixes it.
const app = dedent`
import Uppy from '@uppy/core'
${packages.map((pgk) => `import ${camelcase(pgk)} from '@uppy/${pgk}'`).join('\n')}
import Uppy from '@uppy/core'
${packages.map((pgk) => `import ${camelcase(pgk)} from '@uppy/${pgk}'`).join('\n')}
const uppy = new Uppy()
${packages.map((pkg) => `.use(${camelcase(pkg)})`).join('\n\t')}
const uppy = new Uppy()
${packages.map((pkg) => `.use(${camelcase(pkg)})`).join('\n\t')}
// Keep this here to access uppy in tests
window.uppy = uppy
// Keep this here to access uppy in tests
window.uppy = uppy
`

await fs.writeFile(testUrl, test)
Expand Down
1 change: 0 additions & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"devDependencies": {
"cypress": "^9.0.0",
"cypress-file-upload": "^5.0.8",
"dedent": "^0.7.0",
"deep-freeze": "^0.0.1",
"parcel": "^2.0.1",
"prompts": "^2.4.2",
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17017,7 +17017,6 @@ __metadata:
"@uppy/zoom": "workspace:^"
cypress: ^9.0.0
cypress-file-upload: ^5.0.8
dedent: ^0.7.0
deep-freeze: ^0.0.1
parcel: ^2.0.1
prompts: ^2.4.2
Expand Down

0 comments on commit c2692e4

Please sign in to comment.