Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hopefully running mocha tests again #873

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .github/workflows/Checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,31 @@ 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:
DISPLAY: ':99'
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 -p"
},
"pre-commit": [
"clean",
Expand Down
91 changes: 56 additions & 35 deletions tests/main-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,68 @@ 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(60000);
this.beforeEach(async function()
{
this.timeout(25000); // Estimated pessimistic time taken for the app to the brought up in CI
this.timeout(60000);
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();
const { client } = this.app;
await client.waitUntilWindowLoaded();
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(60000);
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();
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();

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();

Expand All @@ -76,10 +82,12 @@ 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();

Expand All @@ -90,35 +98,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();

// 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');
});
});