Skip to content

Commit

Permalink
✅ Create a chrome level test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr committed Nov 13, 2023
1 parent 1c3194a commit 6ef3b5d
Show file tree
Hide file tree
Showing 17 changed files with 367 additions and 21 deletions.
12 changes: 0 additions & 12 deletions .config/.prettierrc

This file was deleted.

8 changes: 8 additions & 0 deletions .config/webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ exports.default = (env, argv) => {
{ title: 'Settings', folder: 'settings', outFolder: 'settings' },
{ title: 'Bookmarks', folder: 'bookmarks', outFolder: 'bookmarks' },
{ title: 'Credits', folder: 'credits', outFolder: 'credits' },
{ title: 'Test runner', folder: 'tests', outFolder: 'tests' },
],
dev,
)
Expand Down Expand Up @@ -61,6 +62,9 @@ const sharedSettings = (contentFiles, dev) => {
},
resolve: {
extensions: ['.ts', '.mjs', '.js', '.svelte'],
alias: {
'@shared': resolve('src/content/shared'),
},
},

devtool: dev ? 'inline-source-map' : 'source-map',
Expand Down Expand Up @@ -123,6 +127,10 @@ const sharedSettings = (contentFiles, dev) => {
test: /\.(png|jpe?g|gif|svg|webp)$/i,
type: 'asset/resource',
},
{
test: /\.txt$/,
type: 'asset/source',
},
],
},
plugins: [
Expand Down
File renamed without changes.
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"scripts:build": "tsc -p ./tsconfigs/tsconfig.scripts.json",
"script:setup": "node ./.scripts/setup.js",
"script:license-check": "node ./.scripts/license-check.js",
"script:unit-test": "node ./.scripts/unit-test.js",
"app:start": "MOZ_ENABLE_WAYLAND=1 ./.store/rt/quark-runtime -no-remote",
"app:startX": "./.store/rt/quark-runtime -no-remote",
"build": "rm -rf dist && concurrently -c auto pnpm:build-*",
Expand All @@ -28,6 +29,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@tinyhttp/app": "^2.2.1",
"@tsconfig/svelte": "^5.0.2",
"@types/node": "^20.8.4",
"concurrently": "^8.2.1",
Expand All @@ -52,7 +54,8 @@
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-license-plugin": "^4.4.2"
"webpack-license-plugin": "^4.4.2",
"zora": "^5.2.0"
},
"dependencies": {
"@catppuccin/palette": "^0.2.0",
Expand All @@ -65,5 +68,17 @@
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
}
},
"prettier": {
"semi": false,
"singleQuote": true,
"overrides": [
{
"files": "src/prefs.js",
"options": {
"semi": true
}
}
]
}
}
152 changes: 152 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion scripts/license-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { walkDirectory } from './lib/fs.js'
import { autoFix, isValidLicense } from './lib/license.js'
import { failure } from './lib/logging.js'

const IGNORED_FILES = new RegExp('.*\\.(json|patch|md|jpeg|png|gif|tiff|ico)')
const IGNORED_FILES = new RegExp(
'.*\\.(json|patch|md|jpeg|png|gif|tiff|ico|txt)',
)

const shouldFix = argv.includes('--fix')
const filesToCheck = [
Expand Down
35 changes: 35 additions & 0 deletions scripts/unit-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { argv, exit } from 'node:process'
import { App } from '@tinyhttp/app'
import { type ExecaChildProcess, execa } from 'execa'

// If you update this port, you should update the port in the test runner
const TEST_PORT = 3948
const TEST_RUNNER_URL = 'chrome://browser/content/tests/index.html'

const shouldWatch = argv.includes('--watch')
let testProcess: ExecaChildProcess<string>

// This is the way that the test runner communicates with the test app
new App()
.get('/config', (_, res) => void res.send({ shouldWatch }))
.post('/results', (req, res) => {
req.on('data', (chunk: Buffer) => {
console.log(chunk.toString())
})
req.on('close', () => {
res.send('ok')

if (!shouldWatch) {
testProcess?.kill()
exit()
}
})
})
.listen(TEST_PORT)

if (!shouldWatch)
testProcess = execa('./.store/rt/quark-runtime', [
'--no-remote',
'--chrome',
TEST_RUNNER_URL,
])
7 changes: 4 additions & 3 deletions src/content/shared/search/providers/URLProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Provider, type ProviderResult } from '../provider'
import tld from './data/tld.txt'

const URL_REGEX =
/^^(?<protocol>https?:\/\/)?(?<domain>(\w+\.)+(?<tld>\w+))(?<path>\/.*)?$$/gm
/^^(?<protocol>https?:\/\/)?(?<domain>(\w+\.)+(?<tld>\w+))(?<path>\/.*)?$$/m
const tlds = tld
.split('\n')
.filter((tld) => tld.length > 0 && !tld.startsWith('#'))
Expand All @@ -17,14 +17,15 @@ export class URLProvider extends Provider {
if (match === null) return []

const { protocol, domain, tld, path } = match.groups || {}
const uri = `${protocol ?? 'https://'}${domain}.${tld}${path ?? ''}`
const uri = `${protocol || 'https://'}${domain}${path || ''}`

// If it is not a valid tld, don't show it
if (!tlds.includes(tld)) return []
if (!tlds.includes(tld.toUpperCase())) return []

return [
{
title: uri,
// @ts-ignore
url: Services.io.newURI(uri),
icon: `chrome://branding/content/icon32.png`,
},
Expand Down
Loading

0 comments on commit 6ef3b5d

Please sign in to comment.