Skip to content

Commit

Permalink
Add automated tests (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Jun 14, 2022
1 parent ca20e9a commit 1816d8a
Show file tree
Hide file tree
Showing 19 changed files with 19,866 additions and 73 deletions.
35 changes: 21 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
env: {}

# FILE GENERATED WITH: npx ghat fregante/ghatemplates/node
# SOURCE: https://github.com/fregante/ghatemplates
# OPTIONS: {"exclude":["jobs.Test"]}
# FILE GENERATED WITH: npx ghat fregante/content-scripts-register-polyfill/.github/workflows/ci.yml
# SOURCE: https://github.com/fregante/content-scripts-register-polyfill

name: Test

name: CI
on:
- pull_request
- push

jobs:
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: install
run: npm ci || npm install
- name: XO
run: npx xo
- uses: actions/checkout@v3
- run: npm ci
- run: npx xo

Build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: install
run: npm ci || npm install
- name: build
run: npm run build
- uses: actions/checkout@v3
- run: npm ci
- run: npm run build
- run: npm run demo:build

Test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: sudo apt-get install xvfb
- run: npm ci
- run: xvfb-run --auto-servernum npm run jest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ logs
*.map
index.js
index.d.ts
.parcel-cache
dist
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

3 changes: 3 additions & 0 deletions .parcelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@parcel/config-webextension"
}
15 changes: 5 additions & 10 deletions how-to-add-github-enterprise-support-to-web-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import addDomainPermissionToggle from 'webext-domain-permission-toggle';
addDomainPermissionToggle();
```

## manifest.json example
## manifest.json v2 example

```js
{
"version": 2,
"permissions": [
"https://github.com/*",
"contextMenus",
Expand All @@ -49,15 +50,9 @@ addDomainPermissionToggle();
},
"content_scripts": [
{
"matches": [
"https://github.com/*"
],
"css": [
"content.css"
],
"js": [
"content.js"
]
"matches": ["https://github.com/*"],
"css": ["content.css"],
"js": ["content.js"]
}
]
}
Expand Down
8 changes: 5 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function convertPath(file: string): browser.extensionTypes.ExtensionFileOrCode {
return {file: url.pathname};
}

function injectOnExistingTabs(origins: string[], scripts: ContentScripts) {
function injectToExistingTabs(origins: string[], scripts: ContentScripts) {
if (origins.length === 0) {
return;
}
Expand All @@ -42,7 +42,7 @@ async function registerOnOrigins({
const manifest = chrome.runtime.getManifest().content_scripts;

if (!manifest) {
throw new Error('webext-dynamic-content-scripts tried to register scripts on th new host permissions, but no content scripts were found in the manifest.');
throw new Error('webext-dynamic-content-scripts tried to register scripts on the new host permissions, but no content scripts were found in the manifest.');
}

// Register one at a time to allow removing one at a time as well
Expand All @@ -60,7 +60,9 @@ async function registerOnOrigins({
}
}

injectOnExistingTabs(newOrigins || [], manifest);
// May not be needed in the future in Firefox
// https://bugzilla.mozilla.org/show_bug.cgi?id=1458947
injectToExistingTabs(newOrigins || [], manifest);
}

(async () => {
Expand Down
11 changes: 11 additions & 0 deletions jest-puppeteer.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const path = require('path');

module.exports = {
launch: {
headless: false,
args: [
'--disable-extensions-except=' + path.resolve(__dirname, 'test/dist'),
'--window-size=400,800',
],
},
};
Loading

0 comments on commit 1816d8a

Please sign in to comment.