Skip to content

More fixes for test.yml #12

More fixes for test.yml

More fixes for test.yml #12

Workflow file for this run

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: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies and set up ESM
run: |
npm init -y
# Add "type": "module" using jq
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';
import '../surreal.js';
describe('Surreal.js Basic Tests', () => {
it('should have Surreal defined globally', () => {
expect(global.Surreal).to.exist;
});
it('should have a method surrealExampleFunction if exists', () => {
expect(global.Surreal.surrealExampleFunction).to.be.a('function');
});
it('example test: 1 + 1 equals 2', () => {
expect(1 + 1).to.equal(2);
});
it('classadd should add class to element', () => {
expect(global.Surreal.classadd).to.be.a('function');
const el = document.createElement('div');
global.Surreal.classadd('test-class', el);
expect(el.classList.contains('test-class')).to.be.true;
});
});
EOF
- name: Run tests
run: npx mocha test/surreal.test.js