chore(Storybook): Exclude TestRunnerController component for handling test runs
This commit is contained in:
parent
5784f4cd87
commit
8e5cf758fd
|
@ -89,6 +89,10 @@ ApplicationWindow {
|
|||
onReloaded: hotReloaderControls.notifyReload()
|
||||
}
|
||||
|
||||
TestRunnerController {
|
||||
id: testRunnerController
|
||||
}
|
||||
|
||||
SplitView {
|
||||
anchors.fill: parent
|
||||
|
||||
|
@ -190,6 +194,8 @@ ApplicationWindow {
|
|||
figmaPagesCount: currentPageModelItem.object
|
||||
? currentPageModelItem.object.figma.count : 0
|
||||
|
||||
testRunnerController: testRunnerController
|
||||
|
||||
Instantiator {
|
||||
id: currentPageModelItem
|
||||
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
import QtQuick 2.14
|
||||
import QtQuick.Controls 2.14
|
||||
import QtQuick.Layouts 1.14
|
||||
|
||||
import Storybook 1.0
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Layouts 1.15
|
||||
|
||||
ToolBar {
|
||||
id: root
|
||||
|
||||
property string componentName
|
||||
|
||||
property int figmaPagesCount: 0
|
||||
|
||||
required property TestRunnerController testRunnerController
|
||||
|
||||
signal figmaPreviewClicked
|
||||
signal inspectClicked
|
||||
|
||||
|
@ -59,49 +58,54 @@ ToolBar {
|
|||
TestRunnerControls {
|
||||
id: testRunnerControls
|
||||
|
||||
property var testProcess: null
|
||||
readonly property string testFileName: `tst_${root.componentName}.qml`
|
||||
|
||||
onTestFileNameChanged: {
|
||||
if (testRunnerControls.testProcess)
|
||||
testRunnerControls.testProcess.kill()
|
||||
if (testRunnerController.running)
|
||||
testRunnerController.abort()
|
||||
|
||||
testRunnerControls.mode = TestRunnerControls.Mode.Base
|
||||
}
|
||||
|
||||
onRunClicked: {
|
||||
const testsCount = TestsRunner.testsCount(testFileName)
|
||||
|
||||
if (testsCount === 0)
|
||||
return noTestsDialog.open()
|
||||
Connections {
|
||||
target: testRunnerController
|
||||
|
||||
function onStarted() {
|
||||
testRunnerControls.mode = TestRunnerControls.Mode.InProgress
|
||||
}
|
||||
|
||||
const process = TestsRunner.runTests(testFileName)
|
||||
testRunnerControls.testProcess = process
|
||||
|
||||
process.finished.connect((exitCode, exitStatus) => {
|
||||
function onFinished(failedTests, aborted, crashed) {
|
||||
if (testRunnerControls.mode !== TestRunnerControls.Mode.InProgress)
|
||||
return
|
||||
|
||||
if (exitStatus) {
|
||||
if (aborted) {
|
||||
testRunnerControls.mode = TestRunnerControls.Mode.Aborted
|
||||
return
|
||||
}
|
||||
|
||||
if (crashed) {
|
||||
testRunnerControls.mode = TestRunnerControls.Mode.Crashed
|
||||
return
|
||||
}
|
||||
|
||||
if (exitCode)
|
||||
testRunnerControls.mode = TestRunnerControls.Mode.Failed
|
||||
else
|
||||
testRunnerControls.mode = TestRunnerControls.Mode.Success
|
||||
testRunnerControls.mode = failedTests
|
||||
? TestRunnerControls.Mode.Failed
|
||||
: TestRunnerControls.Mode.Success
|
||||
|
||||
testRunnerControls.numberOfFailedTests = exitCode
|
||||
})
|
||||
testRunnerControls.numberOfFailedTests = failedTests
|
||||
}
|
||||
}
|
||||
|
||||
onAbortClicked: {
|
||||
testRunnerControls.testProcess.kill()
|
||||
testRunnerControls.mode = TestRunnerControls.Mode.Aborted
|
||||
onRunClicked: {
|
||||
const testsCount = testRunnerController.getTestsCount(testFileName)
|
||||
|
||||
if (testsCount === 0)
|
||||
return noTestsDialog.open()
|
||||
|
||||
testRunnerController.runTests(testFileName)
|
||||
}
|
||||
|
||||
onAbortClicked: testRunnerController.abort()
|
||||
}
|
||||
|
||||
ToolSeparator {}
|
||||
|
@ -141,7 +145,7 @@ ToolBar {
|
|||
: ""
|
||||
}
|
||||
|
||||
onAccepted: Qt.openUrlExternally(Qt.resolvedUrl(TestsRunner.testsPath()))
|
||||
onAccepted: Qt.openUrlExternally(testRunnerController.getTestsPath())
|
||||
Component.onCompleted: standardButton(Dialog.Ok).text = "Open tests folder"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
import QtQml 2.15
|
||||
|
||||
import Storybook 1.0
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
readonly property alias running: d.running
|
||||
readonly property alias aborted: d.aborted
|
||||
|
||||
signal started
|
||||
signal finished(int failedTests, bool aborted, bool crashed)
|
||||
|
||||
function getTestsCount(testFileName) {
|
||||
return TestsRunner.testsCount(testFileName)
|
||||
}
|
||||
|
||||
function getTestsPath() {
|
||||
return Qt.resolvedUrl(TestsRunner.testsPath())
|
||||
}
|
||||
|
||||
function runTests(testFileName) {
|
||||
console.assert(d.testProcess === null)
|
||||
|
||||
const process = TestsRunner.runTests(testFileName)
|
||||
d.testProcess = process
|
||||
d.running = true
|
||||
|
||||
process.finished.connect((exitCode, exitStatus) => {
|
||||
root.finished(exitCode, d.aborted, exitStatus !== 0)
|
||||
|
||||
d.running = false
|
||||
d.aborted = false
|
||||
})
|
||||
|
||||
started()
|
||||
}
|
||||
|
||||
function abort() {
|
||||
d.aborted = true
|
||||
d.testProcess.kill()
|
||||
}
|
||||
|
||||
readonly property QtObject _d: QtObject {
|
||||
id: d
|
||||
|
||||
property var testProcess: null
|
||||
property bool aborted: false
|
||||
property bool running: false
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ PopupBackground 1.0 PopupBackground.qml
|
|||
SettingsLayout 1.0 SettingsLayout.qml
|
||||
SingleItemProxyModel 1.0 SingleItemProxyModel.qml
|
||||
SourceCodeBox 1.0 SourceCodeBox.qml
|
||||
TestRunnerController 1.0 TestRunnerController.qml
|
||||
TestRunnerControls 1.0 TestRunnerControls.qml
|
||||
singleton FigmaUtils 1.0 FigmaUtils.qml
|
||||
singleton InspectionUtils 1.0 InspectionUtils.qml
|
||||
|
|
Loading…
Reference in New Issue