This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): test output tab, closes #51
- Loading branch information
Showing
17 changed files
with
493 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<script lang="ts"> | ||
import { defineComponent } from 'vue' | ||
export default defineComponent({ | ||
inheritAttrs: false, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<router-link | ||
v-slot="{ isExactActive, href, navigate }" | ||
v-bind="$attrs" | ||
custom | ||
> | ||
<a | ||
v-bind="$attrs" | ||
:href="href" | ||
class="px-4 h-10 inline-flex items-center hover:bg-primary-50 dark:hover:bg-primary-900 relative" | ||
:class="{ | ||
'text-primary-500 dark:text-primary-400': isExactActive, | ||
}" | ||
@click="navigate" | ||
> | ||
<slot /> | ||
|
||
<transition name="scale-x"> | ||
<div | ||
v-if="isExactActive" | ||
class="absolute bottom-0 left-0 w-full h-[2px] bg-primary-500 dark:bg-primary-400" | ||
/> | ||
</transition> | ||
</a> | ||
</router-link> | ||
</template> |
200 changes: 200 additions & 0 deletions
200
packages/peeky-client/src/features/terminal/Terminal.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
<script lang="ts"> | ||
import 'xterm/css/xterm.css' | ||
import { ref, onMounted, watch, onUnmounted, onActivated, computed, defineComponent, PropType } from 'vue' | ||
import { IDisposable, Terminal } from 'xterm' | ||
import { FitAddon } from 'xterm-addon-fit' | ||
import { SearchAddon } from 'xterm-addon-search' | ||
import { WebLinksAddon } from 'xterm-addon-web-links' | ||
import { WebglAddon } from 'xterm-addon-webgl' | ||
// @ts-ignore | ||
import { ResizeObserver } from 'vue-resize' | ||
import { useSettings } from '../settings' | ||
const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].includes(navigator.platform) | ||
const isWebgl2Supported = (() => { | ||
let isSupported = window.WebGL2RenderingContext ? undefined : false | ||
return () => { | ||
if (isSupported === undefined) { | ||
const canvas = document.createElement('canvas') | ||
const gl = canvas.getContext('webgl2', { depth: false, antialias: false }) | ||
isSupported = gl instanceof window.WebGL2RenderingContext | ||
} | ||
return isSupported | ||
} | ||
})() | ||
const defaultTheme = { | ||
foreground: '#1e1e25', | ||
background: '#fff', | ||
cursor: '#ccc', | ||
cursorAccent: '#ddd', | ||
selection: '#00000040', | ||
black: '#000000', | ||
red: '#e83030', | ||
brightRed: '#e83030', | ||
green: '#42b983', | ||
brightGreen: '#42b983', | ||
brightYellow: '#ea6e00', | ||
yellow: '#ea6e00', | ||
magenta: '#e83030', | ||
brightMagenta: '#e83030', | ||
cyan: '#03c2e6', | ||
brightBlue: '#03c2e6', | ||
brightCyan: '#03c2e6', | ||
blue: '#03c2e6', | ||
white: '#d0d0d0', | ||
brightBlack: '#808080', | ||
brightWhite: '#ffffff', | ||
} | ||
const darkTheme = { | ||
...defaultTheme, | ||
foreground: '#fff', | ||
background: '#1e1e25', | ||
cursor: '#A0AEC0', | ||
selection: '#ffffff40', | ||
magenta: '#e83030', | ||
brightMagenta: '#e83030', | ||
} | ||
export default defineComponent({ | ||
components: { | ||
ResizeObserver, | ||
}, | ||
props: { | ||
logs: { | ||
type: Array as PropType<{ type: 'stdout' | 'stderr', text: string }[]>, | ||
required: true, | ||
}, | ||
}, | ||
setup (props) { | ||
const listeners: IDisposable[] = [] | ||
// Theme | ||
const { settings } = useSettings() | ||
const currentTheme = computed(() => { | ||
if (settings.value.darkMode) { | ||
return darkTheme | ||
} | ||
return defaultTheme | ||
}) | ||
watch(currentTheme, value => { | ||
if (term) { | ||
term.options.theme = value | ||
} | ||
}) | ||
// XTerminal | ||
const fitAddon = new FitAddon() | ||
const searchAddon = new SearchAddon() | ||
let term: Terminal | ||
const el = ref(null) | ||
const xtermTarget = ref<HTMLElement | null>(null) | ||
function createTerminal () { | ||
if (!term && xtermTarget.value) { | ||
term = new Terminal({ | ||
theme: currentTheme.value, | ||
scrollback: 4000, | ||
windowsMode: isWindows, | ||
macOptionIsMeta: true, | ||
fontSize: 12, | ||
disableStdin: true, | ||
convertEol: true, | ||
fontFamily: 'Fira Code', | ||
}) | ||
// Addons | ||
term.loadAddon(fitAddon) | ||
term.loadAddon(searchAddon) | ||
term.loadAddon(new WebLinksAddon(undefined, undefined, true)) | ||
term.open(xtermTarget.value) | ||
if (isWebgl2Supported()) { | ||
term.loadAddon(new WebglAddon()) | ||
} | ||
// Scroll | ||
// listeners.push(term.onScroll(position => { | ||
// cached.scroll = position | ||
// })) | ||
} | ||
// Init | ||
fitAddon.fit() | ||
term.focus() | ||
// Initial size is undefined on the server | ||
term.options.theme = currentTheme.value | ||
// https://github.com/xtermjs/xterm.js/issues/291 | ||
// term.scrollToLine(cached.scroll) | ||
// term._core._onScroll.fire(cached.scroll) | ||
for (const log of props.logs) { | ||
term.writeln(log.text) | ||
} | ||
} | ||
onMounted(() => { | ||
createTerminal() | ||
}) | ||
onActivated(() => { | ||
createTerminal() | ||
}) | ||
onUnmounted(() => { | ||
for (const off of listeners) { | ||
off.dispose() | ||
} | ||
listeners.length = 0 | ||
}) | ||
// Element resize | ||
function onElResize () { | ||
if (term) { | ||
fitAddon.fit() | ||
} | ||
} | ||
watch(() => props.logs, value => { | ||
term.clear() | ||
for (const log of props.logs) { | ||
term.writeln(log.text) | ||
} | ||
}) | ||
return { | ||
el, | ||
xtermTarget, | ||
onElResize, | ||
} | ||
}, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div | ||
ref="el" | ||
class="relative p-2 overflow-hidden" | ||
> | ||
<div | ||
ref="xtermTarget" | ||
class="w-full h-full" | ||
/> | ||
|
||
<resize-observer @notify="onElResize()" /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
<script lang="ts" setup> | ||
import { useQuery, useResult } from '@vue/apollo-composable' | ||
import gql from 'graphql-tag' | ||
import { useRoute } from 'vue-router' | ||
import { defineProps, onMounted, ref } from 'vue' | ||
import Terminal from '../terminal/Terminal.vue' | ||
const route = useRoute() | ||
const props = defineProps({ | ||
test: { | ||
type: Object, | ||
required: true, | ||
}, | ||
suite: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}) | ||
const { result } = useQuery(() => gql` | ||
query testLogs ($runId: ID!, $suiteId: ID!, $testId: ID!) { | ||
run (id: $runId) { | ||
id | ||
testSuite: testSuiteById (id: $suiteId) { | ||
id | ||
test: testById (id: $testId) { | ||
id | ||
logs { | ||
type, | ||
text | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`, () => ({ | ||
runId: route.params.runId, | ||
suiteId: props.suite.id, | ||
testId: props.test.id, | ||
}), { | ||
fetchPolicy: 'no-cache', | ||
}) | ||
const logs = useResult(result, [], data => data.run.testSuite.test.logs) | ||
const fontsLoaded = ref(false) | ||
onMounted(async () => { | ||
await document.fonts.load('14px "Fira Code"') | ||
fontsLoaded.value = true | ||
}) | ||
</script> | ||
|
||
<template> | ||
<Terminal | ||
v-if="fontsLoaded" | ||
:logs="logs" | ||
class="w-full h-full" | ||
/> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.