Skip to content

Commit

Permalink
Merge pull request #1336 from gavinr/gh-actions-for-testing-3
Browse files Browse the repository at this point in the history
Automated testing with GitHub actions
  • Loading branch information
gavinr committed Aug 17, 2022
2 parents e1ae96d + 49f519a commit 7ee4b61
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 155 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: CI
on: [push, pull_request]
env:
NODE_VERSION: 16
jobs:
setup:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
check-latest: true
cache: npm

- name: Cache dependencies
id: cache-dependencies
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}

- name: Install dependencies
if: steps.cache-dependencies.outputs.cache-hit != 'true'
run: npm ci

- name: Cache setup
uses: actions/cache@v3
with:
path: ./*
key: ${{ runner.os }}-${{ github.sha }}-setup

build:
needs: setup
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- name: Restore setup
uses: actions/cache@v3
with:
path: ./*
key: ${{ runner.os }}-${{ github.sha }}-setup

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Build project
run: npm run build

- name: Cache build
uses: actions/cache@v3
with:
path: ./*
key: ${{ runner.os }}-${{ github.sha }}-build

lint:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Restore setup
uses: actions/cache@v3
with:
path: ./*
key: ${{ runner.os }}-${{ github.sha }}-setup

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Run lint task
run: npm run lint

test:
needs: build
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
strategy:
fail-fast: false
matrix:
include:
- browser: Chrome1280x1024
- browser: FirefoxTouch
- browser: FirefoxNoTouch
- browser: Edge
os: windows-latest
steps:
- name: Restore build
uses: actions/cache@v3
with:
path: ./*
key: ${{ runner.os }}-${{ github.sha }}-build

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Run tests on ${{ matrix.browser }}
run: npm test -- --browsers ${{ matrix.browser }}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,3 @@ site/build
# Built Files
dist

# so semistandard doesnt lint the folder during CI
travis_phantomjs
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

57 changes: 37 additions & 20 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Karma configuration
// Generated on Fri May 30 2014 15:44:45 GMT-0400 (EDT)

module.exports = function (config) {
var configuration = {

Expand All @@ -9,7 +7,7 @@ module.exports = function (config) {

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai-sinon'],
frameworks: ['mocha', 'sinon-chai'],

// list of files / patterns to load in the browser
// not sure why tests are failing when files are loaded in bulk
Expand Down Expand Up @@ -39,37 +37,60 @@ module.exports = function (config) {
// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_WARN,

// enable / disable colors in the output (reporters and logs)
colors: true,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
autoWatch: false,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [
'Chrome'
// 'ChromeCanary',
// 'Firefox',
// 'Safari',
// 'PhantomJS'
],
browsers: ['Chrome1280x1024'],

customLaunchers: {
Chrome_travis_ci: {
Chrome1280x1024: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
// increased viewport is required for some tests (TODO fix tests)
// https://github.com/Leaflet/Leaflet/issues/7113#issuecomment-619528577
flags: ['--window-size=1280,1024']
},
FirefoxTouch: {
base: 'FirefoxHeadless',
prefs: {
'dom.w3c_touch_events.enabled': 1
}
},
FirefoxNoTouch: {
base: 'FirefoxHeadless',
prefs: {
'dom.w3c_touch_events.enabled': 0
}
}
},

concurrency: 1,

// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,

// Timeout for the client socket connection [ms].
browserSocketTimeout: 30000,

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,

client: {
mocha: {
// eslint-disable-next-line no-undef
forbidOnly: process.env.CI || false
}
},

// Configure the coverage reporters
coverageReporter: {
reporters: [
Expand All @@ -83,9 +104,5 @@ module.exports = function (config) {
}
};

if (process.env.TRAVIS) {
configuration.browsers = ['Chrome_travis_ci'];
}

config.set(configuration);
};

0 comments on commit 7ee4b61

Please sign in to comment.