From 440b192082b151437118f35de31e941f79fd202b Mon Sep 17 00:00:00 2001 From: Thamara Andrade Date: Sun, 16 Oct 2022 22:17:45 -0300 Subject: [PATCH] Running mocha tests again --- .github/workflows/Checks.yml | 16 ++++-- package.json | 2 +- tests/main-window.js | 98 +++++++++++++++++++++--------------- 3 files changed, 71 insertions(+), 45 deletions(-) diff --git a/.github/workflows/Checks.yml b/.github/workflows/Checks.yml index dc59c94d5..449c5e6be 100644 --- a/.github/workflows/Checks.yml +++ b/.github/workflows/Checks.yml @@ -24,6 +24,9 @@ jobs: sudo chmod +x /tmp/chromedriver/chromedriver /tmp/chromedriver/chromedriver & sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & + - name: ' Create COV_REPORT' + run: | + mkdir COV_REPORT - name: ' Tests' shell: bash env: @@ -31,16 +34,21 @@ jobs: run: | npm ci npm run test:jest - - name: ' Create COV_REPORT' - run: | - mkdir COV_REPORT - name: ' Copy jest results' run: | cp coverage_jest/coverage-final.json COV_REPORT/coverage-final-jest.json + - name: ' Tests - Mocha' + run: npm run test:mocha + shell: bash + if: matrix.os == 'ubuntu-latest' + - name: ' Copy mocha results' + run: | + cp coverage_jest/coverage-final.json COV_REPORT/coverage-final-mocha.json + if: matrix.os == 'ubuntu-latest' - name: ' CodeCov' uses: codecov/codecov-action@v2 with: token: ${{ secrets.CODECOV_TOKEN }} - files: COV_REPORT/coverage-final-jest.json + files: COV_REPORT/coverage-final-*.json name: codecov-${{ matrix.os }} verbose: true \ No newline at end of file diff --git a/package.json b/package.json index d4d0d510d..2a8eaee34 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "start": "electron .", "test": "npm-run-all test:*", "test:jest": "jest --runInBand --detectOpenHandles --verbose --colors", - "test:mocha": "nyc --reporter=lcov --reporter=json mocha tests/*" + "test:mocha": "nyc --reporter=lcov --reporter=json mocha tests/* --bail" }, "pre-commit": [ "clean", diff --git a/tests/main-window.js b/tests/main-window.js index 08a5c2300..1eab5badc 100644 --- a/tests/main-window.js +++ b/tests/main-window.js @@ -10,64 +10,67 @@ process.env.NODE_ENV = 'test'; const months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; const weekDay = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ]; +function log(msg) +{ + console.log(`${(new Date()).toISOString().substr(0, 19)}: ${msg}`); +} + describe('Application launch', function() { - // deepcode ignore UseArrowFunction: => will not work on here - beforeEach(function() + this.timeout(30000); + this.beforeEach(async function() { - this.timeout(25000); // Estimated pessimistic time taken for the app to the brought up in CI this.app = new Application({ path: electronPath, - args: [path.join(__dirname, '..')] + args: [path.join(__dirname, '..')], + waitTimeout: 30000, + quitTimeout: 1000 }); - return this.app.start(); + log('Start app...') + await this.app.start(); + log('App started.') }); - afterEach(function() + this.afterEach(async function() { - this.timeout(10000); // Estimated pessimistic time taken for the app to be stopped in CI + this.timeout(30000); + log(`App is running: ${this.app && this.app.isRunning()}`) if (this.app && this.app.isRunning()) { - return this.app.stop(); + log('Stop app...'); + await this.app.stop(); + log('App stoped'); } }); it('App opens correctly', async function() { + log('Running test ' + this.test.title); const { client, browserWindow } = this.app; - await client.waitUntilWindowLoaded(); + await client.waitUntilWindowLoaded(10000); const title = await browserWindow.getTitle(); assert.equal(title, 'Time to Leave'); + log('Running test - Done'); }); it('Calendar opens on Current Month/Year', async function() { + log('Running test ' + this.test.title); const { client } = this.app; - await client.waitUntilWindowLoaded(); + await client.waitUntilWindowLoaded(10000); const monthYear = await client.$('#month-year'); const monthYearText = await monthYear.getText(); const today = new Date(); assert.equal(monthYearText, `${months[today.getMonth()]} ${today.getFullYear()}`); - }); - - it('Change to Day View', async function() - { - const { client } = this.app; - await client.waitUntilWindowLoaded(); - - const switchViewBtn = await client.$('#switch-view'); - await switchViewBtn.click(); - const headerDate = await client.$('#header-date'); - const headerDateText = await headerDate.getText(); - const today = new Date(); - assert.equal(headerDateText, `${weekDay[today.getDay()]}, ${months[today.getMonth()]} ${today.getDate()}, ${today.getFullYear()}`); + log('Running test - Done'); }); it('Calendar change to previous Month', async function() { + log('Running test ' + this.test.title); const { client } = this.app; - await client.waitUntilWindowLoaded(); + await client.waitUntilWindowLoaded(10000); const prevMonth = await client.$('#prev-month'); prevMonth.click(); @@ -76,12 +79,14 @@ describe('Application launch', function() const today = new Date(); const prevMonthDate = new Date(today.getFullYear(), today.getMonth(), -1); assert.equal(monthYearText, `${months[prevMonthDate.getMonth()]} ${prevMonthDate.getFullYear()}`); + log('Running test - Done'); }); it('Calendar change to next Month', async function() { + log('Running test ' + this.test.title); const { client } = this.app; - await client.waitUntilWindowLoaded(); + await client.waitUntilWindowLoaded(10000); const nextMonth = await client.$('#next-month'); nextMonth.click(); @@ -90,35 +95,48 @@ describe('Application launch', function() const today = new Date(); const nextMonthDate = new Date(today.getFullYear(), today.getMonth() + 1, 1); assert.equal(monthYearText, `${months[nextMonthDate.getMonth()]} ${nextMonthDate.getFullYear()}`); + log('Running test - Done'); }); - it('Calendar change to pervious Day', async function() + it('Day View - Current, yesterday and tomorrow', async function() { + log('Running test ' + this.test.title); const { client } = this.app; - await client.waitUntilWindowLoaded(); + await client.waitUntilWindowLoaded(10000); + + // Switch to Day View const switchViewBtn = await client.$('#switch-view'); await switchViewBtn.click(); + + // Check that changed to current day + let headerDate = await client.$('#header-date'); + let headerDateText = await headerDate.getText(); + const today = new Date(); + assert.equal(headerDateText, `${weekDay[today.getDay()]}, ${months[today.getMonth()]} ${today.getDate()}, ${today.getFullYear()}`); + + // Check that prev day go back to yesterday const prevDay = await client.$('#prev-day'); prevDay.click(); - const headerDate = await client.$('#header-date'); - const headerDateText = await headerDate.getText(); - const today = new Date(); + headerDate = await client.$('#header-date'); + headerDateText = await headerDate.getText(); const previousDayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1); assert.equal(headerDateText, `${weekDay[previousDayDate.getDay()]}, ${months[previousDayDate.getMonth()]} ${previousDayDate.getDate()}, ${previousDayDate.getFullYear()}`); - }); - it('Calendar change to next Day', async function() - { - const { client } = this.app; - await client.waitUntilWindowLoaded(); - const switchViewBtn = await client.$('#switch-view'); - await switchViewBtn.click(); + // Back to current day + const currentDay = await client.$('#current-day'); + currentDay.click(); + headerDate = await client.$('#header-date'); + headerDateText = await headerDate.getText(); + assert.equal(headerDateText, `${weekDay[today.getDay()]}, ${months[today.getMonth()]} ${today.getDate()}, ${today.getFullYear()}`); + + // Check that next day go back to tomorrow const nextDay = await client.$('#next-day'); nextDay.click(); - const headerDate = await client.$('#header-date'); - const headerDateText = await headerDate.getText(); - const today = new Date(); + headerDate = await client.$('#header-date'); + headerDateText = await headerDate.getText(); const nextDayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1); assert.equal(headerDateText, `${weekDay[nextDayDate.getDay()]}, ${months[nextDayDate.getMonth()]} ${nextDayDate.getDate()}, ${nextDayDate.getFullYear()}`); + + log('Running test - Done'); }); });