Skip to content

Commit

Permalink
Improve testing & CI (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr authored Jan 15, 2024
1 parent 31d0ce2 commit 5ed7adf
Show file tree
Hide file tree
Showing 21 changed files with 1,263 additions and 67 deletions.
95 changes: 62 additions & 33 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,35 @@ on:
push:

jobs:
license_check:
name: License Check
build:
name: Build
runs-on: ubuntu-latest

permissions:
contents: read
statuses: write

steps:
- name: Clone repo
uses: actions/checkout@v4
- uses: actions/setup-node@v3
# Prep commit statuses
- name: Prep Statuses (License Check)
uses: myrotvorets/set-commit-status-action@master
with:
node-version: 18

- name: Setup pnpm
uses: pnpm/action-setup@v2
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
context: License Check
- name: Prep Statuses (Build)
uses: myrotvorets/set-commit-status-action@master
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
context: Build
- name: Prep Statuses (Tests)
uses: myrotvorets/set-commit-status-action@master
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
context: Tests

- name: Install dependencies & RT
run: pnpm install
- name: Check licenses
run: pnpm script:license-check

build:
name: Build
needs: [license_check]
runs-on: ubuntu-latest

steps:
- name: Clone repo
uses: actions/checkout@v4
- uses: actions/setup-node@v3
Expand All @@ -54,6 +44,7 @@ jobs:
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
Expand All @@ -68,18 +59,56 @@ jobs:
- name: Install dependencies & RT
run: pnpm install

- name: Check licenses
id: license_check
continue-on-error: true
run: pnpm script:license-check
- name: Report Statuses (License Check)
uses: myrotvorets/set-commit-status-action@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ steps.license_check.outcome }}
context: License Check

- name: Build
id: build
run: pnpm build
- name: Report Statuses (Build)
uses: myrotvorets/set-commit-status-action@master
if: always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ steps.build.outcome }}
context: Build

- name: Run tests
uses: coactions/setup-xvfb@v1
id: tests
with:
run: pnpm script:unit-test
- name: Report Statuses (Tests)
uses: myrotvorets/set-commit-status-action@master
if: always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ steps.tests.outcome }}
context: Tests

- name: Create test summary
uses: test-summary/action@v2
with:
paths: '.store/*.tap'
if: always()

- name: De-symlink
run: rsync .store/rt/ rt_dist/ -a --copy-links

- name: Compress artifact
run: tar -cvjSf testing-browser.tar.bz2 rt_dist/

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: testing_browser
path: rt_dist/
path: testing-browser.tar.bz2
9 changes: 9 additions & 0 deletions apps/content/src/tests/browser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import pageactions from './pageactions'

export default async function () {
await pageactions()
}
5 changes: 5 additions & 0 deletions apps/content/src/tests/browser/pageactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

export default async function () {}
2 changes: 2 additions & 0 deletions apps/content/src/tests/tests.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import browser from './browser'
import { manageTests } from './manager'
import shared from './shared'

async function tests() {
await shared()
await browser()
}

await manageTests(tests)
Expand Down
29 changes: 29 additions & 0 deletions apps/content/static/gtests.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<!doctype html>
<html lang="en">
<head>
<title>Test runner</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<h1>Test runner</h1>

<script type="module">
import { TestManager } from 'resource://app/modules/TestManager.sys.mjs'
import 'resource://app/modules/tests/integrations/_index.sys.mjs'

// @ts-check
/// <reference types="@browser/link" />
console.log('start import')

console.log('import int')

console.log('call')
TestManager.call()
</script>
</body>
</html>
74 changes: 74 additions & 0 deletions apps/modules/lib/TestManager.sys.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// @ts-check
/// <reference types="@browser/link" />
import {
createTAPReporter,
hold,
report,
test,
} from 'resource://app/modules/zora.sys.mjs'

const TEST_PORT = 3948

/** @typedef {import('resource://app/modules/TestManager.sys.mjs').TestManagerInterface} TestManagerInst */

/** @implements {TestManagerInst} */
class TestManagerSingleton {
/**
* @private
* @type {import('resource://app/modules/TestManager.sys.mjs').Test[]}
*/
tests = []

/**
* @param {string} name
* @param {import('resource://app/modules/TestManager.sys.mjs').BrowserTestFunction} spec
* @param {import('resource://app/modules/zora.sys.mjs').ITestOptions} [options]
*/
browserTest(name, spec, options) {
this.tests.push({ name, spec, options })
}

async call() {
hold()

console.log('Starting tests')
let testIndex = 0
for (const { name, spec, options } of this.tests) {
testIndex += 1
console.time(`test-${testIndex}`)
/** @type {Window} */
// @ts-expect-error Incorrect type gen
const window = Services.ww.openWindow(
// @ts-expect-error Incorrect type generation
null,
Services.prefs.getStringPref('app.content'),
'_blank',
'chrome,dialog=no,all',
undefined,
)

await new Promise((res) =>
window.addEventListener('DOMContentLoaded', res),
)
const testFn = spec(window)
await test(name, testFn, options)
window.close()
console.time(`test-${testIndex}`)
}

let log = ''
const reporter = createTAPReporter({ log: (s) => (log += s + '\n') })
await report({ reporter })

await fetch(`http://localhost:${TEST_PORT}/results`, {
method: 'POST',
body: log,
})
}
}

export const TestManager = new TestManagerSingleton()
6 changes: 1 addition & 5 deletions apps/modules/lib/mitt.sys.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
/* @not-mpl
* MIT License
*
* Copyright (c) 2021 Jason Miller
Expand Down
Loading

0 comments on commit 5ed7adf

Please sign in to comment.