Skip to content

Commit

Permalink
test: implement karma and browserstack tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tivie committed Mar 27, 2022
1 parent db571fb commit 9a3e714
Show file tree
Hide file tree
Showing 19 changed files with 2,292 additions and 213 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"env": {
"es6": true
},
"rules": {
"indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": 2}],
"curly": [2, "all"],
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/browserstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: 'BrowserStack Test'
on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]
jobs:
ubuntu-job:
name: 'BrowserStack Test on Ubuntu'
runs-on: ubuntu-latest
steps:

- name: 'BrowserStack Env Setup' # Invokes the setup-env action
uses: browserstack/github-actions/setup-env@master
with:
username: ${{ secrets.BROWSERSTACK_USERNAME }}
access-key: ${{ secrets.BROWSERSTACK_ACCESSKEY }}

- name: 'BrowserStack Local Tunnel Setup' # Invokes the setup-local action
uses: browserstack/github-actions/setup-local@master
with:
local-testing: start
local-identifier: random

# The next 3 steps are for building the web application to be tested and starting the web server on the runner environment

- name: 'Checkout the repository'
uses: actions/checkout@v2

- name: '🚚 Upgrade NPM'
run: npm install -g npm

- name: 'Use Node.js 17.x'
uses: actions/setup-node@v2
with:
node-version: 17.x
cache: 'npm'

- name: 'Concatenate src files for testing'
run: grunt concat:test

- name: 'Running test on BrowserStack with Karma'
run: karma start karma.browserstack.js

- name: 'BrowserStackLocal Stop' # Terminating the BrowserStackLocal tunnel connection
uses: browserstack/github-actions/setup-local@master
with:
local-testing: stop
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
node_modules
npm-debug.log
/*.test.*
*.log
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/**/*.js
build/**/*.js
src/options.js
bin/*
/karma.browserstack.js
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"smarttabs": true,
"onevar": true,
"globals": {
"angular": true,
"module": true,
"define": true,
"window": true,
Expand Down
50 changes: 25 additions & 25 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ module.exports = function (grunt) {
require('quiet-grunt');
}

/**
* Load common tasks for legacy and normal tests
*/
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-endline');
grunt.loadNpmTasks('grunt-contrib-jshint');

// Project configuration.
var config = {
pkg: grunt.file.readJSON('package.json'),
Expand Down Expand Up @@ -124,57 +134,47 @@ module.exports = function (grunt) {
}
},

simplemocha: {
mochaTest: {
functional: {
src: 'test/functional/**/*.js',
options: {
globals: ['should'],
timeout: 3000,
ignoreLeaks: true,
reporter: 'spec'
reporter: 'spec',
require: ['test/bootstrap.js']
}
},
unit: {
src: 'test/unit/**/*.js',
options: {
globals: ['should'],
timeout: 3000,
ignoreLeaks: true,
reporter: 'spec'
reporter: 'spec',
require: ['test/bootstrap.js']
}
},
single: {
options: {
globals: ['should'],
timeout: 3000,
ignoreLeaks: false,
reporter: 'spec'
reporter: 'spec',
require: ['test/bootstrap.js']
}
},
cli: {
src: 'test/unit/cli.js',
options: {
globals: ['should'],
timeout: 3000,
ignoreLeaks: false,
reporter: 'spec'
reporter: 'spec',
require: ['test/bootstrap.js']
}
}
}
};

grunt.initConfig(config);

/**
* Load common tasks for legacy and normal tests
*/
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-endline');
grunt.loadNpmTasks('grunt-contrib-jshint');

/**
* Generate Changelog
*/
Expand Down Expand Up @@ -210,23 +210,23 @@ module.exports = function (grunt) {
grunt.registerTask('single-test', function (file) {
'use strict';
grunt.config.merge({
simplemocha: {
mochaTest: {
single: {
src: file
}
}
});

grunt.task.run(['lint', 'concat:test', 'simplemocha:single', 'clean']);
grunt.task.run(['lint', 'concat:test', 'mochaTest:single', 'clean']);
});

/**
* Tasks
*/
grunt.registerTask('test', ['clean', 'lint', 'concat:test', 'simplemocha:unit', 'simplemocha:functional', 'clean']);
grunt.registerTask('test-functional', ['concat:test', 'simplemocha:functional', 'clean']);
grunt.registerTask('test-unit', ['concat:test', 'simplemocha:unit', 'clean']);
grunt.registerTask('test-cli', ['clean', 'lint', 'concat:test', 'simplemocha:cli', 'clean']);
grunt.registerTask('test', ['clean', 'lint', 'concat:test', 'mochaTest:unit', 'mochaTest:functional', 'clean']);
grunt.registerTask('test-functional', ['concat:test', 'mochaTest:functional', 'clean']);
grunt.registerTask('test-unit', ['concat:test', 'mochaTest:unit', 'clean']);
grunt.registerTask('test-cli', ['clean', 'lint', 'concat:test', 'mochaTest:cli', 'clean']);

grunt.registerTask('performance', ['concat:test', 'performancejs', 'clean']);
grunt.registerTask('build', ['test', 'concat:dist', 'concat:cli', 'uglify:dist', 'uglify:cli', 'endline']);
Expand Down
12 changes: 9 additions & 3 deletions TASKS.TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@
## CLI
- [ ] Refactor the CLI
- [ ] **#381**: *Support for src and dst directories in showdown cli*
- [ ] **#584**: *Fails to read from stdin*
- [ ] **#554**: *CLI not working with jsdom v10*
- [X] **#584**: *Fails to read from stdin*
- [X] **#554**: *CLI not working with jsdom v10*
## Other stuff
- [X] Regexp rewrite for more performance oompf
- [ ] Full unit testing
- [X] Full unit testing
- [ ] Better error reporting
## Stuff that probably won't make it to v2.0
Expand Down Expand Up @@ -138,3 +138,9 @@ This should address:
- [ ] Options
- [ ] Extensions (and the new event system)
- [ ] Cookbook (with stuff for backwards compatibility, specially regarding removed options)

## Browser Testing

- [X] Implement unit tests in Karma
- [ ] Implement functional tests in Karma
- [ ] Integrate with browserstack
64 changes: 64 additions & 0 deletions karma.browserstack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module.exports = function (config) {
config.set({
// global config of your BrowserStack account
browserStack: {
username: process.env.BROWSERSTACK_USERNAME,
accessKey: process.env.BROWSERSTACK_ACCESSKEY
},

// define browsers
customLaunchers: {
bstack_chrome_windows: {
base: 'BrowserStack',
browser: 'chrome',
browser_version: '72.0',
os: 'Windows',
os_version: '10'
},
bstack_firefox_windows: {
base: 'BrowserStack',
browser: 'firefox',
browser_version: '98.0',
os: 'Windows',
os_version: '10'
},
//dropped support for IE 10
bstack_ie10_windows: {
base: 'BrowserStack',
browser: 'ie',
browser_version: '10',
os: 'Windows',
os_version: '7'
},
//dropped support for IE 10
bstack_ie11_windows: {
base: 'BrowserStack',
browser: 'ie',
browser_version: '11',
os: 'Windows',
os_version: '10'
},
bstack_iphoneX: {
base: 'BrowserStack',
browser: 'safari',
device: 'iPhone X',
os: 'ios',
real_mobile: true,
os_version: '11.0'
}
},

browsers: ['bstack_chrome_windows', 'bstack_firefox_windows', 'bstack_ie11_windows', 'bstack_iphoneX'],
frameworks: ['mocha', 'chai'],
reporters: ['dots', 'BrowserStack'],
files: [
{ pattern: '.build/showdown.js'},
{ pattern: 'src/options.js'},
// tests
{ pattern: 'test/unit/showdown*.js' },
{ pattern: 'test/functional/showdown*.js' },
],
singleRun: true,
concurrency: Infinity
});
};
36 changes: 36 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = function (config) {
config.set({
client: {
captureConsole: true
},
browserConsoleLogOptions: {
level: 'log',
format: '%b %T: %m',
terminal: true
},
logLevel: config.LOG_LOG,
frameworks: ['mocha', 'chai'],
files: [
{ pattern: '.build/showdown.js'},
{ pattern: 'src/options.js'},
// tests
{ pattern: 'test/unit/showdown*.js' },
{ pattern: 'test/functional/showdown*.js' },
],
reporters: ['progress'],
port: 9876, // karma web server port
colors: true,
browsers: ['ChromeHeadless', 'FirefoxHeadless', 'jsdom'],
autoWatch: false,
singleRun: true, // Karma captures browsers, runs the tests and exits
//concurrency: Infinity,
customLaunchers: {
'FirefoxHeadless': {
base: 'Firefox',
flags: [
'-headless',
]
}
},
});
};
Loading

0 comments on commit 9a3e714

Please sign in to comment.