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

feat: electron 17 and playwright tests #1937

Merged
merged 12 commits into from
Feb 4, 2022
Merged

feat: electron 17 and playwright tests #1937

merged 12 commits into from
Feb 4, 2022

Conversation

hacdias
Copy link
Member

@hacdias hacdias commented Dec 6, 2021

Closes #1902

Comment on lines +4 to +9
if (process.env.NODE_ENV === 'test') {
const path = require('path')

app.setPath('home', process.env.HOME)
app.setPath('userData', path.join(process.env.HOME, 'data'))
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, this was somewhat on the include.js file that we'd require using the flag -r when booting Electron. However, for some reason, even though we used setPath('userData', ...) there, the value wouldn't be reflected after the actual application started. Thus, I found this to be the best solution.

@@ -63,7 +64,7 @@ module.exports = async function (ctx) {
}

log.end()
updateStatus(STATUS.STARTING_FINISHED)
updateStatus(STATUS.STARTING_FINISHED, id)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not scraping the logs anymore, so we send the peer id on the event once the startup is finished.

@hacdias
Copy link
Member Author

hacdias commented Dec 6, 2021

@lidel the move is not as straightforward as I thought. Tests are failing on Ubuntu and partially failing on Windows. I will take a look on this Friday when I have more time. I left some code annotations on why I changed some things.

@hacdias
Copy link
Member Author

hacdias commented Dec 10, 2021

Update: I will work on the Linux and Windows testing. I have to setup some VMs so it'll take a bit longer.

Update 2: all tests pass locally on a Ubuntu installation. Hmm...

Update 3: Windows working. It was just missing setting IPFS_PATH as an environment variable as we did before. Overriding all variables on Windows is an hassle. Maybe in the future we can look into how to properly replace %APPDATA% and %USERPROFILE% in tests. This way, we can add a test where we don't explicitly set the IPFS_PATH such that we can verify if the repository is created on the correct place.

I think Linux is related to the test setup, as it works locally on an Ubuntu VM.

@hacdias
Copy link
Member Author

hacdias commented Dec 13, 2021

@lidel could you please take a look into the Ubuntu tests? They all time out but I can't reproduce the problem.

@hacdias
Copy link
Member Author

hacdias commented Dec 17, 2021

Update: managed to reproduce on an Ubuntu server instance.

Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pushing here ❤️
Sadly, I've run out of time this week – will get back to this in Jan.

@lidel lidel self-requested a review December 17, 2021 23:46
@hacdias
Copy link
Member Author

hacdias commented Jan 3, 2022

Just a note: the tests on macOS on the CI seem unstable, randomly failing because with the error electronApplication.close: Browser closed.. I cannot reproduce that error locally and didn't figure out yet why is it happening. Maybe microsoft/playwright#5130?

@hacdias
Copy link
Member Author

hacdias commented Jan 24, 2022

On #1961, for Electron 15.x version, we get a more specific error:

     electron.launch: Unable to open X display!
================================
Most likely this is because there is no X server available.
Use 'xvfb-run' on Linux to launch your tests with an emulated display server.
For example: 'xvfb-run npm run test:e2e'
================================

So it's definitely related to the xvfb thingy.

@hacdias hacdias force-pushed the use-playwright branch 2 times, most recently from 3e86eba to d17b338 Compare January 24, 2022 10:46
@hacdias
Copy link
Member Author

hacdias commented Jan 24, 2022

I tried different combinations of commands to run xvfb, but none of them seems to work correctly. Perhaps updating the Xvfb action would fix whatever issue is happening. When I try to update it, it says that this repository can only run very specific versions of actions. I don't have permissions to update that and check.

@lidel lidel mentioned this pull request Feb 3, 2022
@lidel lidel changed the title feat: move to playwright feat: electron 16 and playwright tests Feb 3, 2022
@lidel lidel changed the title feat: electron 16 and playwright tests feat: electron 17 and playwright tests Feb 4, 2022
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @hacdias for doing the heavy lifting, and apologies for being slow on this one ❤️

Poked at the CI issue, and it turned out to be caused by the meaning of env parameter passed to electron.launch – details inline.

CI is green, I switched to Electron 17 and works as expected, merging! 🚀

@@ -100,7 +100,7 @@ jobs:
run: npm run test

- name: Test end-to-end
uses: GabrielBB/xvfb-action@f040be23a619e5ec34116f24098ad3626ceab681 # v1.4
uses: GabrielBB/xvfb-action@86d97bde4a65fe9b290c0b3fb92c2c4ed0e5302d # v1.6
Copy link
Member

@lidel lidel Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This was not impacting build (i had the same timeout on the local Linux box), but I bumped version and safelisted this third-party action as part of investigation.

@@ -9,7 +9,7 @@
"start": "cross-env NODE_ENV=development electron .",
"lint": "standard",
"test": "cross-env NODE_ENV=test mocha test/unit/**/*.spec.js",
"test:e2e": "xvfb-maybe cross-env NODE_ENV=test LIBP2P_ALLOW_WEAK_RSA_KEYS=1 mocha test/e2e/**/*.e2e.js --exit",
"test:e2e": "xvfb-maybe cross-env NODE_ENV=test playwright test test/e2e/launch.e2e.test.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ switched to runner native to playright (just to avoid any bugs caused by legacy mocha stack)

"cross-env": "^7.0.3",
"delay": "^5.0.0",
"dirty-chai": "^2.0.1",
"dotenv": "^14.2.0",
"electron": "13.6.7",
"electron": "^17.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cats-in-shower-caps19

Comment on lines +30 to +34
env: Object.assign({}, process.env, {
NODE_ENV: 'test',
HOME: home,
IPFS_PATH: repoPath
}
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ @hacdias this fixed the weird CI failure on Linux.

It was caused by the difference in how env field works here.
In playwright, passed env fully replaces process.env for greater control, so we were missing some variables created by X11/Xvfb. This restores them, solving e2 on Linux.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Thanks for figuring it out :)

return { peerId }
async function daemonReady (app) {
const peerId = await app.evaluate(async ({ ipcMain }) => new Promise((resolve, reject) => {
ipcMain.on('ipfsd', (status, peerId) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ really cool, switching to more sane way of reading ipfsd status makes tests run really fast now!

}

it('creates a repository on startup', async function () {
test('creates a repository on startup', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ this and below changes are just refactor from mocha and chai to modern @playwright/test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Unblock Electron Update
2 participants