tauri/cli/tauri.js/test/jest/fixtures/app/dist/index.html

118 lines
3.4 KiB
HTML
Raw Normal View History

2020-03-07 19:40:24 +03:00
<!DOCTYPE html>
<html>
2020-03-07 19:40:24 +03:00
<body>
<script>
function callBackEnd(route, args) {
console.log(route)
console.log(args)
2020-03-07 19:40:24 +03:00
var xhr = new XMLHttpRequest()
xhr.onload = function () {
console.log(route, args, 'done', xhr.status)
}
xhr.onerror = function () {
console.log(route, args, 'error with ' + xhr.status)
}
2020-03-07 19:40:24 +03:00
xhr.open('POST', 'http://localhost:7000/' + route)
xhr.setRequestHeader('Content-type', 'application/json')
xhr.send(JSON.stringify(args))
}
function reply(args) {
return callBackEnd('reply', args)
}
function sendError(error) {
return callBackEnd('error', error)
}
function testFs(dir) {
var contents = 'TAURI E2E TEST FILE'
var commandSuffix = (dir ? 'WithDir' : '')
var options = {
dir: dir || null
}
return window.__TAURI__.fs.writeFile({
file: 'tauri-test.txt',
contents: contents
}, options).then(function (res) {
reply({
cmd: 'writeFile' + commandSuffix
})
return window.__TAURI__.fs.readTextFile('tauri-test.txt', options).then(function (res) {
if (res === contents) {
reply({
cmd: 'readFile' + commandSuffix
})
return window.__TAURI__.fs.readDir('.', options).then(res => {
reply({
cmd: 'readDir' + commandSuffix
})
return window.__TAURI__.fs.copyFile('tauri-test.txt', 'tauri-test-copy.txt', options)
.then(function (res) {
reply({
cmd: 'copyFile' + commandSuffix
})
return window.__TAURI__.fs.createDir('tauri-test-dir', options).then(function (res) {
reply({
cmd: 'createDir' + commandSuffix
})
return window.__TAURI__.fs.removeDir('tauri-test-dir', options).then(function (res) {
reply({
cmd: 'removeDir' + commandSuffix
})
})
}).then(function (res) {
return window.__TAURI__.fs.renameFile('tauri-test.txt', 'tauri.testt.txt', options)
.then(function (res) {
reply({
cmd: 'renameFile' + commandSuffix
})
return Promise.all([
window.__TAURI__.fs.removeFile('tauri.testt.txt', options),
window.__TAURI__.fs.removeFile('tauri-test-copy.txt', options)
]).then(function (res) {
reply({
cmd: 'removeFile' + commandSuffix
})
})
})
})
})
})
} else {
sendError('expected "' + contents + '" found "' + res + '"')
}
})
}).catch(sendError)
}
window.__TAURI__.event.listen('reply', function (res) {
reply({
cmd: 'listen'
})
})
2020-03-07 19:40:24 +03:00
window.onTauriInit = function () {
window.__TAURI__.event.emit('hello')
}
testFs(null).then(function () {
testFs(window.__TAURI__.fs.Dir.Config)
})
setTimeout(function () {
window.__TAURI__.invoke({
cmd: 'exit'
})
}, 15000)
2020-03-07 19:40:24 +03:00
</script>
</body>
</html>