Added Change Log #29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test Surreal.js in Emulated Browser | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
- name: Download surreal.js | |
run: curl -o surreal.js https://raw.githubusercontent.com/gnat/surreal/refs/heads/main/surreal.js | |
- name: Add global export at bottom of surreal.js for node | |
run: | | |
cat << 'EOF' >> surreal.js | |
if (typeof window !== 'undefined') { window.surreal = surreal; } else if (typeof globalThis !== 'undefined') { globalThis.surreal = surreal; } | |
EOF | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Install dependencies and configure ESM | |
run: | | |
npm init -y | |
jq '. + {type: "module"}' package.json > tmp.json && mv tmp.json package.json | |
npm install mocha chai jsdom jsdom-global | |
- name: Create test file | |
run: | | |
mkdir -p test | |
cat << 'EOF' > test/surreal.test.js | |
import 'jsdom-global/register.js'; | |
import { expect } from 'chai'; | |
// Load surreal.js (adds Surreal to window) | |
import '../surreal.js'; | |
describe('Surreal Test Suite', () => { | |
it('Test suite works?', () => { | |
expect(1 + 1).to.equal(2); | |
}); | |
it('should have surreal defined globally on window', () => { | |
expect(window.surreal).to.exist; | |
}); | |
it('should have a method classRemove if exists', () => { | |
expect(window.surreal.classRemove).to.be.a('function'); | |
}); | |
it('classAdd should add class to element', () => { | |
expect(window.surreal.classAdd).to.be.a('function'); | |
const el = document.createElement('div'); | |
window.surreal.classAdd(el, 'test-class'); | |
expect(el.classList.contains('test-class')).to.be.true; | |
}); | |
}); | |
EOF | |
- name: Run tests | |
run: npx mocha test/surreal.test.js |