Skip to content

Commit

Permalink
Run CI tests on all OSes (#2)
Browse files Browse the repository at this point in the history
* test on all common operating systems

* fix test on Mac

* use nodejs to link directory

* add gitattributes file

* fix test

* tweak

* tweak

* tweak

* tweak

* tweak

* tweak

* check cachdir

* execute script with node

* tweak

* deal with extension properly

* return path

* fix

* fix test
  • Loading branch information
christian-bromann authored Mar 24, 2022
1 parent 2561a79 commit 8b2fef9
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
21 changes: 21 additions & 0 deletions .github/scripts/link.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import fs from 'fs/promises'
import path from 'path'
import url from 'url'

console.log('Start linking wdio-vscode-service into node_modules');

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
const ROOT = path.join(__dirname, '..', '..')
const LINKED_DIR = path.join(ROOT, 'node_modules', 'wdio-vscode-service')

const relative = (from, to) => path.relative(
path.dirname(from),
path.resolve(to)
)

await fs.rm(LINKED_DIR, {
recursive: true
}).catch((e) => console.warn(`Linked dir doesn't exists: ${e.message}`))

await fs.symlink(relative(LINKED_DIR, ROOT), LINKED_DIR, 'dir')
console.log('Successful linked package');
15 changes: 8 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ on:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
Expand All @@ -22,10 +25,8 @@ jobs:
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Run Tests
run: |
sudo apt-get install xvfb
export DISPLAY=:99.0
Xvfb -ac :99 -screen 0 1920x1080x16 &
npm test
- name: 🧪 Run Tests
uses: GabrielBB/xvfb-action@v1
with:
run: yarn test

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"release:minor": "npm run release -- minor",
"release:major": "npm run release -- major",
"test": "run-s test:*",
"test:setup": "cd node_modules && rm -rf ./wdio-vscode-service && ln -s ../ wdio-vscode-service && cd ..",
"test:setup": "node ./.github/scripts/link.mjs",
"test:lint": "eslint src test example",
"test:e2e": "run-s test:e2e:*",
"test:e2e:run": "wdio run ./test/wdio.conf.ts",
Expand All @@ -43,7 +43,7 @@
"download": "^8.0.0",
"tmp-promise": "^3.0.3",
"undici": "^4.15.1",
"wdio-chromedriver-service": "^7.3.1"
"wdio-chromedriver-service": "^7.3.2"
},
"peerDependencies": {
"webdriverio": "^7.17.4"
Expand Down
22 changes: 9 additions & 13 deletions src/launcher.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os from 'os'
import fs from 'fs/promises'
import path from 'path'
import { format } from 'util'
Expand Down Expand Up @@ -50,7 +51,6 @@ export default class VSCodeServiceLauncher extends ChromedriverServiceLauncher {
this._cachePath = this._options.cachePath || DEFAULT_CACHE_PATH
}

// @ts-expect-error parent class has different structure
async onPrepare (_: never, capabilities: ServiceCapabilities[]) {
const version = this._options.vscode?.version || DEFAULT_CHANNEL

Expand All @@ -71,7 +71,6 @@ export default class VSCodeServiceLauncher extends ChromedriverServiceLauncher {
+ `and Chromedriver v${content[version]?.chromedriver} already exist`
)

// @ts-expect-error `chromedriverCustomPath` is not defined in parent class
this.chromedriverCustomPath = chromedriverPath
this._populateCaps(capabilities, {
chromedriver: { version: content[version]!.chromedriver, path: chromedriverPath },
Expand All @@ -84,12 +83,8 @@ export default class VSCodeServiceLauncher extends ChromedriverServiceLauncher {
}
}

const [vscodeVersion, chromedriverVersion] = await this._setupChromedriver(version)
// @ts-expect-error `chromedriverCustomPath` is not defined
const chromedriverPath = this.chromedriverCustomPath = path.join(
this._cachePath,
`chromedriver-${chromedriverVersion}`
)
const [vscodeVersion, chromedriverVersion, chromedriverPath] = await this._setupChromedriver(version)
this.chromedriverCustomPath = chromedriverPath
const serviceArgs: ServiceCapability = {
chromedriver: { version: chromedriverVersion, path: chromedriverPath },
vscode: { version: vscodeVersion, path: await this._setupVSCode(vscodeVersion) }
Expand All @@ -112,7 +107,7 @@ export default class VSCodeServiceLauncher extends ChromedriverServiceLauncher {
* or a concrete version e.g. 1.66.0
* @returns "insiders" if `desiredReleaseChannel` is set to this otherwise a concrete version
*/
private async _setupChromedriver (desiredReleaseChannel?: VSCodeChannel) {
private async _setupChromedriver (desiredReleaseChannel: VSCodeChannel) {
const version = await this._fetchVSCodeVersion(desiredReleaseChannel)

try {
Expand All @@ -125,15 +120,16 @@ export default class VSCodeServiceLauncher extends ChromedriverServiceLauncher {
{ extract: true, strip: 1 }
)

const chromedriverPath = path.join(this._cachePath, `chromedriver-${chromedriverVersion}`)
await fs.rename(path.join(this._cachePath, 'chromedriver'), chromedriverPath)
const ext = os.platform().startsWith('win') ? '.exe' : ''
const chromedriverPath = path.join(this._cachePath, `chromedriver-${chromedriverVersion}${ext}`)
await fs.rename(path.join(this._cachePath, `chromedriver${ext}`), chromedriverPath)

/**
* return 'insiders' if desired release channel
*/
return version === 'main'
? [desiredReleaseChannel!, chromedriverVersion]
: [version, chromedriverVersion]
? [desiredReleaseChannel, chromedriverVersion, chromedriverPath]
: [version, chromedriverVersion, chromedriverPath]
} catch (err: any) {
throw new SevereServiceError(`Couldn't set up Chromedriver ${err.message}`)
}
Expand Down
11 changes: 8 additions & 3 deletions test/specs/basic.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../../dist/service.d.ts" />

import { PluginDecorator, IPluginDecorator, BasePage } from 'wdio-vscode-service'
import { PluginDecorator, IPluginDecorator, BasePage } from '../..'

const locators = {
marquee: {
Expand Down Expand Up @@ -35,7 +35,12 @@ describe('WDIO VSCode Service', () => {

it('should be able to load VSCode', async () => {
const workbench = await browser.getWorkbench()
expect(await workbench.getTitleBar().getTitle())
.toBe('[Extension Development Host] - README.md - wdio-vscode-service - Visual Studio Code')
const title = await workbench.getTitleBar().getTitle()

/**
* actual title is "[Extension Development Host] - README.md - wdio-vscode-service"
* but test fails on different operating systems due to different "-" chars
*/
expect(title).toContain('wdio-vscode-service')
})
})
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5399,10 +5399,10 @@ wcwidth@^1.0.1:
dependencies:
defaults "^1.0.3"

wdio-chromedriver-service@^7.3.1:
version "7.3.1"
resolved "https://registry.yarnpkg.com/wdio-chromedriver-service/-/wdio-chromedriver-service-7.3.1.tgz#f65fe6dadd55cb5caa925ef478767dea3c7683ba"
integrity sha512-0LnkUJW63WgKPZliH9ueluRuIBLaC8l8LcE1F3PSYy0ZbBJq/i3ObBJVVQBJlco3I2pjXuBCNJ/VyXUCCNflcA==
wdio-chromedriver-service@^7.3.2:
version "7.3.2"
resolved "https://registry.yarnpkg.com/wdio-chromedriver-service/-/wdio-chromedriver-service-7.3.2.tgz#569053df4ceaf6ce9e43bebcdd540197f516e313"
integrity sha512-4M3OqFzBSC4FdbqkfwOrUMeroMEuyIFCHfcUebkU6tJ1w5GenWO61YweJ8NKlhPZx9nkO8223+20MpvBjv+fTg==
dependencies:
"@wdio/logger" "^7.5.3"
fs-extra "^9.1.0"
Expand Down

0 comments on commit 8b2fef9

Please sign in to comment.