Skip to content

Commit

Permalink
(CI/tests) prepare for running multiple electron versions (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthijsBurgh authored Jul 8, 2024
1 parent 66adeb4 commit ef33a4a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/nodeCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, ubuntu-latest, windows-latest]
os: [ubuntu-latest]
node: [16]
electron_version: [27, 28, 29, 30, 31]
include:
- os: windows-latest
commandPrefix: ''
- os: ubuntu-20.04
commandPrefix: xvfb-run
node: 16
command_prefix: ''
electron_version: 31
- os: ubuntu-latest
commandPrefix: xvfb-run
command_prefix: xvfb-run
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -39,10 +40,17 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ matrix.os }}-yarn-node-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
key: ${{ matrix.os }}-yarn-node-${{ matrix.node }}-electron-${{ matrix.electron_version }}-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ matrix.os }}-yarn-node-${{ matrix.node }}-electron-${{ matrix.electron_version }}-
${{ matrix.os }}-yarn-node-${{ matrix.node }}-
${{ matrix.os }}-yarn-node-
- name: Electron version
id: electron-version
shell: bash
run: |
echo "$(jq -M '.devDependencies.electron = "^${{ matrix.electron_version }}.0.0"' -- package.json)" > package.json
cat package.json
- name: yarn install
uses: nick-fields/retry@v3
with:
Expand All @@ -53,12 +61,14 @@ jobs:
run: yarn lint
- name: yarn test
uses: nick-fields/retry@v3
env:
ELECTRON_VERSION: ${{ matrix.electron_version }}
with:
timeout_minutes: 5
max_attempts: 3
command: ${{ matrix.commandPrefix }} yarn run test:ci
command: ${{ matrix.command_prefix }} yarn run test:ci
- name: Upload coverage to Codecov
if: ${{ matrix.os == 'ubuntu-latest' && matrix.node == 16}}
if: ${{ matrix.os == 'ubuntu-latest' && matrix.node == 16 && matrix.electron_version == 31 }}
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
5 changes: 4 additions & 1 deletion __tests__/createProject.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const fs = require('fs-extra')
// Prevent electron-builder from installing app deps
jest.mock('electron-builder/out/cli/install-app-deps.js')

const electronVersion = process.env.ELECTRON_VERSION || 31
const electronRequirement = `${electronVersion}.0.0` // Fixed version

const createProject = async (projectName, useTS, customPlugins = {}) => {
// Prevent modification of import
const preset = {
Expand All @@ -25,7 +28,7 @@ const createProject = async (projectName, useTS, customPlugins = {}) => {
// electron-builder requires that an exact version of electron is provided,
// unless electron is already installed
version: 'file:' + process.cwd(),
electronBuilder: { electronVersion: '31.0.0', addTests: true }
electronBuilder: { electronVersion: electronRequirement, addTests: true }
}
preset.plugins = { ...preset.plugins, ...customPlugins }
const projectPath = (p) =>
Expand Down
9 changes: 6 additions & 3 deletions __tests__/generator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const generator = require('../generator')
const fs = require('fs')
jest.mock('fs')

const electronVersion = process.env.ELECTRON_VERSION || 31
const electronRequirement = `^${electronVersion}.0.0`

// Mock the generator api
let pkg = {}
let completionCb
Expand All @@ -24,7 +27,7 @@ beforeEach(() => {
if (path === 'apiResolve_./package.json') {
return JSON.stringify({
scripts: {},
devDependencies: { electron: '^31.0.0' }
devDependencies: { electron: electronRequirement }
})
}
// return mock content
Expand All @@ -34,7 +37,7 @@ beforeEach(() => {
jest.clearAllMocks()
})
const runGenerator = () =>
generator(mockApi, { electronBuilder: { electronVersion: '^31.0.0' } })
generator(mockApi, { electronBuilder: { electronVersion: electronRequirement } })

describe('.gitignore', () => {
test('extends gitignore if it exists', () => {
Expand Down Expand Up @@ -80,7 +83,7 @@ describe('.gitignore', () => {
if (path === 'apiResolve_./package.json') {
return JSON.stringify({
scripts: {},
devDependencies: { electron: '^31.0.0' }
devDependencies: { electron: electronRequirement }
})
}
// return mock content
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@vue/eslint-config-typescript": "^12.0.0",
"@vuepress/plugin-google-analytics": "^1.8.0",
"ci-info": "^4.0.0",
"electron": "^31.1.0",
"electron": "^29.0.0",
"electron-devtools-installer": "^3.1.0",
"electron-playwright-helpers": "^1.5.5",
"eslint": "^8.56.0",
Expand Down

0 comments on commit ef33a4a

Please sign in to comment.