Skip to content

Instantly share code, notes, and snippets.

@etpinard
Last active August 29, 2020 07:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etpinard/f328c38536360ff37c0de62172c01617 to your computer and use it in GitHub Desktop.
Save etpinard/f328c38536360ff37c0de62172c01617 to your computer and use it in GitHub Desktop.
Jasmine tests in headless chromium xvfb process
Jasmine tests in headless chromium xvfb process
node_modules
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script src="node_modules/jasmine-core/lib/console/console.js"></script>
<script>
var jasmine = jasmineRequire.core(jasmineRequire)
jasmineRequire.console(jasmineRequire, jasmine)
var jasmineEnv = jasmine.getEnv()
var consoleReporter = new jasmine.ConsoleReporter({
print: function print(message) {
console.log(message + '\x03\b')
},
onComplete: function onComplete(isSuccess) {
var exitCode = isSuccess ? 0 : 1
console.info('All tests completed!' + exitCode)
},
showColors: true
})
jasmineEnv.addReporter(consoleReporter)
Object.assign(window, jasmineEnv)
</script>
<script src="./test.js"></script>
<script>window.execute()</script>
</body>
</html>
{
"name": "headless-chromium-jasmine-tests",
"version": "1.0.0",
"description": "Jasmine tests in headless chromium xvfb process",
"scripts": {
"test": "run-headless-chromium index.html --ignore-gpu-blacklist"
},
"keywords": [],
"author": "Étienne Tétreault-Pinard",
"license": "MIT",
"dependencies": {
"jasmine-core": "^2.5.2",
"run-headless-chromium": "^0.1.1"
}
}
describe('first', function() {
it('1 is 1', function() {
expect(1).toEqual(1)
})
it('2 is 2', function() {
expect(2).toEqual(2)
})
})
describe('webgl support', function() {
it('should work', function(done) {
var gl
var canvas
try {
canvas = document.createElement('canvas')
gl = canvas.getContext('webgl')
} catch(err) {
gl = null
}
expect(!!gl).toBe(true)
done()
})
it('should have a devicePixelRatio window property', function() {
expect(window.devicePixelRatio).toEqual(1)
})
})
describe('plotly.js WebGL', function() {
var gd = document.createElement('div')
document.body.appendChild(gd)
it('should load library', function() {
expect(typeof Plotly).toEqual('object')
})
it('should generate WebGL graph (3D case)', function(done) {
Plotly.newPlot(gd, [{
type: 'scatter3d',
x: [1, 2, 3],
y: [1, 2, 3],
z: [2, 1, 2]
}])
.then(function() {
expect(typeof gd._fullLayout.scene._scene).toEqual('object')
return Plotly.toImage(gd)
})
.then(function(img) {
expect(img.length).toEqual(21914)
})
.then(function() {
Plotly.purge(gd)
done()
})
})
it('should generate WebGL graph (2D case)', function(done) {
Plotly.newPlot(gd, [{
type: 'scattergl',
x: [1, 2, 3],
y: [1, 2, 1]
}])
.then(function() {
expect(typeof gd._fullLayout._plots.xy._scene2d).toEqual('object')
return Plotly.toImage(gd)
})
.then(function(img) {
expect(img.length).toEqual(21062)
})
.then(function() {
Plotly.purge(gd)
done()
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment