From b4fdcdb0df5967541904310cf5a0fa69945acccb Mon Sep 17 00:00:00 2001 From: Llewelyn Date: Sat, 26 Jun 2021 13:32:00 +0200 Subject: [PATCH 1/2] updating mocha/spectron and command --- app/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/package.json b/app/package.json index bdbe013b..9948c910 100644 --- a/app/package.json +++ b/app/package.json @@ -7,7 +7,7 @@ "scripts": { "postinstall": "node ../build/createDocumentnavigation.js && markdown-html resources/Documentation/WritingWithInk.md -s resources/Documentation/documentation.css -o renderer/documentation/embedded.html", "start": "electron main-process/main.js", - "test": "./node_modules/mocha/bin/mocha", + "test": "node ./node_modules/mocha/bin/mocha", "generate-locale": "node ../build/generateLocale.js" }, "repository": { @@ -31,8 +31,8 @@ "electron": "^4.2.0", "jsdom": "^16.5.1", "markdown-html": "^0.0.8", - "mocha": "^4.0.1", - "spectron": "^3.8.0" + "mocha": "^9.0.1", + "spectron": "^6.0.0" }, "dependencies": { "chokidar": "^3.3.1", From 3b18671980ca675206d5faa8c6e8ce21123fcde6 Mon Sep 17 00:00:00 2001 From: Llewelyn Date: Sat, 26 Jun 2021 13:32:20 +0200 Subject: [PATCH 2/2] fixing tests --- app/test/test.js | 78 ++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/app/test/test.js b/app/test/test.js index 8a60a65b..a1b70e3e 100644 --- a/app/test/test.js +++ b/app/test/test.js @@ -10,6 +10,10 @@ const inkyPathsByPlatform = { "win32": "../Inky-win32-x64/Inky.exe" }; +const app = new Application({ + path: inkyPathsByPlatform[process.platform] +}) + chai.should(); chai.use(chaiAsPromised); @@ -17,66 +21,76 @@ describe('application launch tests', function () { this.timeout(10000) beforeEach(function () { - this.app = new Application({ - path: inkyPathsByPlatform[process.platform] - }) - return this.app.start().then(function (app) { - chaiAsPromised.transferPromiseness = app.transferPromiseness; - return app; - }); + chaiAsPromised.transferPromiseness = app.transferPromiseness; + return app.start(); }) afterEach(function () { - if (this.app && this.app.isRunning()) { - return this.app.stop() + if (app && app.isRunning()) { + app.mainProcess.exit(0); } }) it('shows an initial window', function () { - return this.app.client.getWindowCount().then(function (count) { - assert.equal(count, 1) - }) + return app.client + .getWindowCount() + .should.eventually.equal(1); }) it('reads the title', function () { const title = "Untitled.ink"; - return this.app.client.getText('.title') + + return app.client + .getHTML('.title', false) .should.eventually.equal(title); }) it('opens the menu', function () { - return this.app.client.click('.icon-menu') - .element('.sidebar') - .should.eventually.exist + const cssPropValue = "block"; + + return app.client + .click('.icon-menu') + .getCssProperty('.sidebar','display').then(function (property){ + return property.value; + }).should.eventually.equal(cssPropValue); }) + }) describe('compiles hello world game', function () { this.timeout(10000) beforeEach(function () { - this.app = new Application({ - path: inkyPathsByPlatform[process.platform] - }) - return this.app.start().then(function (app) { - chaiAsPromised.transferPromiseness = app.transferPromiseness; - return app; + chaiAsPromised.transferPromiseness = app.transferPromiseness; + return app.start().then(function () { + + // A bug with setValue() means it doesn't properly clear the element + // hence the element is cleared by simulating pressing the delete key + + for (let i = 0; i < 125; i++) { + app.client.setValue('.ace_text-input', "\ue017").pause(50); + }; + + return app.client.setValue('.ace_text-input', "\ue017"); }); }) afterEach(function () { - if (this.app && this.app.isRunning()) { - return this.app.stop() + if (app && app.isRunning()) { + app.mainProcess.exit(0); } }) it('writes and reads hello world', function () { const input = "Hello World!"; - return this.app.client + + return app.client .setValue('.ace_text-input', input) .pause(2000) - .getText('.storyText') - .should.eventually.equal(input) + .getText('.storyText:nth-of-type(1)').then(function(value){ + return value.join(''); + }) + .should.eventually.equal(input); }) it('writes and selects a choice', function () { @@ -84,7 +98,7 @@ describe('compiles hello world game', function () { const resultChoice = "Hello back"; const resultAnswer = "Nice to hear from you!"; - return this.app.client + return app.client .setValue('.ace_text-input', input) .pause(2000) .click('.choice') @@ -99,19 +113,19 @@ describe('compiles hello world game', function () { const input = "Hello World! \n * [Hello back] \n Nice to hear from you! \n -> END"; const resultAnswer = "Nice to hear from you!"; - return this.app.client + return app.client .setValue('.ace_text-input', input) .pause(2000) .click('.choice') .pause(2000) - .getText('.storyText:nth-of-type(2)') - .should.eventually.equal(resultAnswer) + .getText('.storyText:nth-of-type(3)') + .should.eventually.equal(resultAnswer); }) it('shows TODOs', function() { const input = "-\n * Rock\n * Paper\n * Scissors\nTODO: Make this more interesting" - return this.app.client + return app.client .setValue('.ace_text-input', input) .pause(2000) .getText('.issuesMessage')