mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-22 02:01:49 +03:00
6a21965ff3
* chore: add prettier for js/ts formatting * fix lint-staged to object * test commit * format all * lock file bump * eslint extends prettier This will let us skip rules in eslint that prettier can control. Prettier for styles, eslint for code errors. * add prettier config * roll back to what we had with eslint settings * skip mutation observer * add prettier typescript eslint * run prettier in lint workflow * format:check script * turn off space before function in eslint it is fighting with prettier * fix dir in workflow * remove semis * add api to eslint * shift eslint ignore comment after prettier format * ignore errors that currently exist * build:typevalidators * replace was broken on typevalidator build * try pushing up error * format * try removing working dir from eslint workflow * try node 12 * fix indent in action * bump eslint * fix supposeded error and try another * try breaking eslint * try building in action * adjust action paths again * need dot * remove build * fix(tauri.js/eslint): escape glob * * fix(tauri.js): ignore lint error * Create prettier-taurijs.md Co-authored-by: Noah Klayman <noahklayman@gmail.com>
100 lines
2.3 KiB
JavaScript
100 lines
2.3 KiB
JavaScript
const path = require('path')
|
|
const fixtureSetup = require('../fixtures/app-test-setup')
|
|
const distDir = path.resolve(fixtureSetup.fixtureDir, 'app', 'dist')
|
|
|
|
function startDevServer() {
|
|
const http = require('http')
|
|
const { statSync, createReadStream } = require('fs')
|
|
const app = http.createServer((req, res) => {
|
|
if (req.method === 'GET') {
|
|
if (req.url === '/') {
|
|
const indexPath = path.join(distDir, 'index.html')
|
|
const stat = statSync(indexPath)
|
|
res.writeHead(200, {
|
|
'Content-Type': 'text/html',
|
|
'Content-Length': stat.size
|
|
})
|
|
createReadStream(indexPath).pipe(res)
|
|
}
|
|
}
|
|
})
|
|
|
|
const port = 7001
|
|
|
|
const server = app.listen(port)
|
|
return {
|
|
server,
|
|
url: `http://localhost:${port}`
|
|
}
|
|
}
|
|
|
|
function runDevTest(tauriConfig) {
|
|
fixtureSetup.initJest('app')
|
|
const dev = require('api/dev')
|
|
return new Promise(async (resolve, reject) => {
|
|
try {
|
|
const { promise, runner } = dev(tauriConfig)
|
|
|
|
const isRunning = require('is-running')
|
|
let success = false
|
|
const checkIntervalId = setInterval(async () => {
|
|
if (!isRunning(runner.pid) && !success) {
|
|
const failedCommands = Object.keys(responses)
|
|
.filter((k) => responses[k] === null)
|
|
.join(', ')
|
|
server.close(() => reject("App didn't reply to " + failedCommands))
|
|
}
|
|
}, 2000)
|
|
|
|
const { server, responses } = fixtureSetup.startServer(async () => {
|
|
success = true
|
|
clearInterval(checkIntervalId)
|
|
// wait for the app process to be killed
|
|
setTimeout(async () => {
|
|
try {
|
|
await runner.stop()
|
|
} catch {}
|
|
resolve()
|
|
}, 2000)
|
|
})
|
|
await promise
|
|
} catch (error) {
|
|
reject(error)
|
|
}
|
|
})
|
|
}
|
|
|
|
describe('Tauri Dev', () => {
|
|
const build = {
|
|
distDir: distDir
|
|
}
|
|
|
|
const devServer = startDevServer()
|
|
|
|
it.each`
|
|
url
|
|
${devServer.url}
|
|
${distDir}
|
|
`('works with dev pointing to $url', ({ url }) => {
|
|
const runningDevServer = url.startsWith('http')
|
|
const promise = runDevTest({
|
|
build: {
|
|
...build,
|
|
devPath: url
|
|
},
|
|
ctx: {
|
|
debug: true,
|
|
dev: true
|
|
}
|
|
})
|
|
|
|
promise.then(() => {
|
|
if (runningDevServer) {
|
|
devServer.server.close()
|
|
}
|
|
})
|
|
|
|
return promise
|
|
})
|
|
})
|