Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add several tests to templates #109

Merged
merged 25 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f496cb6
Simplify create command via CLI
cezaraugusto Jun 20, 2024
5ba9274
Add tests for the CLI
cezaraugusto Jun 20, 2024
73da596
Add tests for the "init" template
cezaraugusto Jun 20, 2024
a3d59f0
Add tests/update ChatGPT template
cezaraugusto Jun 20, 2024
bb9b325
Split tests into CLI + Create
cezaraugusto Jun 20, 2024
99edae8
Add fixtures for the upcoming build test
cezaraugusto Jun 20, 2024
52c2363
Add build tests
cezaraugusto Jun 21, 2024
c03b8b3
Add build tests
cezaraugusto Jun 21, 2024
a2c3870
cli/create/build tests ok
cezaraugusto Jun 21, 2024
030c9b6
Normalize fixture files
cezaraugusto Jun 21, 2024
0f63265
Fix create deleting the folder before build runs
cezaraugusto Jun 21, 2024
4902e8b
cli/create/build command tests ok
cezaraugusto Jun 21, 2024
edf96cd
Re-use test helper methods
cezaraugusto Jun 21, 2024
ed25ae9
Update all templates to use similar structure
cezaraugusto Jun 22, 2024
0e59d3a
Add tests for the "create" command against templates
cezaraugusto Jun 23, 2024
6754582
Add fixtures for all templates
cezaraugusto Jun 23, 2024
2366199
Fix failing build test for chatgpt
cezaraugusto Jun 23, 2024
19e0a34
Prevent naming conflict spot by Jest
cezaraugusto Jun 23, 2024
aa640a6
Add cli tests to ci
cezaraugusto Jun 23, 2024
a84cf9f
Add a way for turbo to pipe CI tests
cezaraugusto Jun 23, 2024
052147d
Add new test scripts to package.json
cezaraugusto Jun 23, 2024
2334ca7
Update CI scripts
cezaraugusto Jun 23, 2024
3bc347c
Update Preact template
cezaraugusto Jun 23, 2024
acad020
Lint files
cezaraugusto Jun 24, 2024
0c2c9ba
Update lock file
cezaraugusto Jun 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: extension:build
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn
- name: Run compiler
run: yarn compile
- name: Run `extenion build` command
run: yarn test:build
13 changes: 13 additions & 0 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: extension:cli
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn
- name: Run compiler
run: yarn compile
- name: Run `extenion` cli without arguments
run: yarn test:cli
13 changes: 13 additions & 0 deletions .github/workflows/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: extension:create
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn
- name: Run compiler
run: yarn compile
- name: Run extenion create command
run: yarn test:create
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"lint": "eslint . --config .eslintrc.js",
"release": "dotenv -- turbo run compile && changeset publish",
"test": "dotenv -- turbo run test",
"test:build": "dotenv -- turbo run test:build",
"test:create": "dotenv -- turbo run test:create",
"test:cli": "dotenv -- turbo run test:cli",
"test:watch": "dotenv -- turbo run test:watch",
"types": "tsc --noEmit --project tsconfig.json",
"version-packages": "changeset version",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export default function browserConfig(
'--disable-features=DialMediaRouteProvider',
// Don't send hyperlink auditing pings
'--no-pings',
// Ensure the side panel is visible. This is used for testing the side panel feature.
'--enable-features=SidePanelUpdates',

// Flags to pass to Chrome
// Any of http://peter.sh/experiments/chromium-command-line-switches/
Expand Down
72 changes: 10 additions & 62 deletions programs/cli/cli.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The statement that imports semver can be deleted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, deleted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code refactoring is very good.

Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import type {CreateOptions} from '@extension-create/create'
import type {DevOptions} from '@extension-create/develop/extensionDev'
import type {StartOptions} from '@extension-create/develop/extensionStart'
import type {BuildOptions} from '@extension-create/develop/extensionBuild'
import type {PreviewOptions} from '@extension-create/develop/extensionPreview'
// import type {PreviewOptions} from '@extension-create/develop/extensionPreview'
import type {BrowsersSupported} from './types'

// Modules
import createExtension from '@extension-create/create'
import {
extensionDev,
extensionStart,
extensionBuild,
extensionBuild
// extensionPreview
} from '@extension-create/develop'

Expand All @@ -34,29 +34,14 @@ import packageJson from './package.json'
// Before all, check for updates.
checkUpdates(packageJson)

if (semver.lte(process.version, '18.0.0')) {
messages.unsupportedNodeVersion()
process.exit(1)
}

const extensionJs = program

// ███████╗██╗ ██╗████████╗███████╗███╗ ██╗███████╗██╗ ██████╗ ███╗ ██╗
// ██╔════╝╚██╗██╔╝╚══██╔══╝██╔════╝████╗ ██║██╔════╝██║██╔═══██╗████╗ ██║
// █████╗ ╚███╔╝ ██║ █████╗ ██╔██╗ ██║███████╗██║██║ ██║██╔██╗ ██║
// ██╔══╝ ██╔██╗ ██║ ██╔══╝ ██║╚██╗██║╚════██║██║██║ ██║██║╚██╗██║
// ███████╗██╔╝ ██╗ ██║ ███████╗██║ ╚████║███████║██║╚██████╔╝██║ ╚████║
// ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝
// ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗
// ██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
// ██║ ██████╔╝█████╗ ███████║ ██║ █████╗
// ██║ ██╔══██╗██╔══╝ ██╔══██║ ██║ ██╔══╝
// ╚██████╗██║ ██║███████╗██║ ██║ ██║ ███████╗
// ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝

if (process.env.EXTENSION_ENV === 'development') {
console.log(`Running extension via ${packageJson.name}...`)
}
// ███████╗██╗ ██╗████████╗███████╗███╗ ██╗███████╗██╗ ██████╗ ███╗ ██╗ ██╗███████╗
// ██╔════╝╚██╗██╔╝╚══██╔══╝██╔════╝████╗ ██║██╔════╝██║██╔═══██╗████╗ ██║ ██║██╔════╝
// █████╗ ╚███╔╝ ██║ █████╗ ██╔██╗ ██║███████╗██║██║ ██║██╔██╗ ██║ ██║███████╗
// ██╔══╝ ██╔██╗ ██║ ██╔══╝ ██║╚██╗██║╚════██║██║██║ ██║██║╚██╗██║ ██ ██║╚════██║
// ███████╗██╔╝ ██╗ ██║ ███████╗██║ ╚████║███████║██║╚██████╔╝██║ ╚████║██╗╚█████╔╝███████║
// ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚════╝ ╚══════╝

extensionJs
.name(packageJson.name)
Expand All @@ -83,45 +68,8 @@ extensionJs
'-t, --template <template-name>',
'specify a template for the created project'
)
.action(async function (
pathOrRemoteUrl: string,
{
browser = 'chrome',
template,
...otherCommandOptions
}: CreateOptions & DevOptions & StartOptions & BuildOptions & PreviewOptions
) {
switch (pathOrRemoteUrl) {
case 'dev':
for (const vendor of vendors(browser)) {
await extensionDev(pathOrRemoteUrl, {
mode: 'development',
browser: vendor as any,
...otherCommandOptions
})
}
break
case 'start':
for (const vendor of vendors(browser)) {
await extensionStart(pathOrRemoteUrl, {
mode: 'production',
browser: vendor as any,
...otherCommandOptions
})
}
break
case 'build':
for (const vendor of vendors(browser)) {
await extensionBuild(pathOrRemoteUrl, {
browser: vendor as any,
...otherCommandOptions
})
}
break
default:
await createExtension(pathOrRemoteUrl, {template})
break
}
.action(async function (pathOrRemoteUrl: string, {template}: CreateOptions) {
await createExtension(pathOrRemoteUrl, {template})
})

// ██████╗ ███████╗██╗ ██╗
Expand Down
3 changes: 1 addition & 2 deletions programs/cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/*.spec.ts']
testEnvironment: 'node'
}
6 changes: 5 additions & 1 deletion programs/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
"url": "https://cezaraugusto.com"
},
"scripts": {
"watch": "yarn compile --watch",
"compile:readme-files": "node ./scripts/copyMarkdownFilesToCli.js",
"compile:tailwind-config": "node ./scripts/copyTailwindConfig.js",
"compile:stylelint-config": "node ./scripts/copyStylelintConfig.js",
"compile:cli": "tsup-node ./cli.ts --format cjs --dts --target=node18",
"compile": "yarn compile:readme-files && yarn compile:tailwind-config && yarn compile:stylelint-config &&yarn compile:cli",
"clean": "rm -rf dist",
"test": "jest"
"before:test": "./spec/fixtures/install-npm-deps-for-fixtures.sh",
"test:build": "npm run before:test && jest spec/build.spec.ts",
"test:cli": "npm run before:test && jest spec/cli.spec.ts",
"test:create": "npm run before:test && jest spec/create.spec.ts"
},
"keywords": [
"zero-config",
Expand Down
126 changes: 126 additions & 0 deletions programs/cli/spec/build.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// ██████╗██╗ ██╗
// ██╔════╝██║ ██║
// ██║ ██║ ██║
// ██║ ██║ ██║
// ╚██████╗███████╗██║
// ╚═════╝╚══════╝╚═╝

import path from 'path'
import {ALL_TEMPLATES, DEFAULT_TEMPLATE, BROWSERS} from './fixtures/constants'
import {
extensionProgram,
distFileExists,
removeAllTemplateFolders
} from './fixtures/helpers'

describe('extension build', () => {
beforeEach(async () => {
await removeAllTemplateFolders()
})

describe('running built-in templates', () => {
it.each(ALL_TEMPLATES)(
`builds an extension created via "$name" template`,
async (template) => {
const extensionPath = path.join(__dirname, 'fixtures', template.name)
await extensionProgram(`build ${extensionPath}`)

// Expect manifest file to exist
expect(
distFileExists(template.name, BROWSERS[0], 'manifest.json')
).toBeTruthy()

// TODO: cezaraugusto test ui context files output

if (template.name !== 'init') {
expect(
distFileExists(template.name, BROWSERS[0], 'icons/icon_16.png')
).toBeTruthy()
expect(
distFileExists(template.name, BROWSERS[0], 'icons/icon_48.png')
).toBeTruthy()
}
},
80000
)
})

describe('using the --browser flag', () => {
it.each(ALL_TEMPLATES)(
`builds the "$name" extension template across all browsers`,
async (template) => {
const extensionPath = path.join(__dirname, 'fixtures', template.name)
// Firefox is skippeed because it can't handle service workers.
const [chrome, edge /*, firefox */] = BROWSERS

await extensionProgram(`build ${extensionPath} --browser=chrome,edge`)

expect(distFileExists(template.name, chrome)).toBeTruthy()
expect(distFileExists(template.name, edge)).toBeTruthy()
},
50000
)
})

describe.skip('using the --polyfill flag', () => {
it.skip.each(ALL_TEMPLATES)(
`builds an extension created via "$name" template with the polyfill code`,
async (template) => {
const extensionPath = path.join(__dirname, 'fixtures', template.name)

await extensionProgram(`build ${extensionPath} --polyfill`)

// TODO cezaraugusto test this
},
50000
)
})

describe('using the --zip flag', () => {
it.each([DEFAULT_TEMPLATE])(
`builds and zips the distribution files of an extension created via "$name" template`,
async (template) => {
const extensionPath = path.join(__dirname, 'fixtures', template.name)

await extensionProgram(`build ${extensionPath} --zip`)

expect(distFileExists(template.name, 'chrome')).toBeTruthy()
},
50000
)

it.each([DEFAULT_TEMPLATE])(
`builds and zips the source files of an extension created via "$name" template`,
async (template) => {
const extensionPath = path.join(__dirname, 'fixtures', template.name)

await extensionProgram(`build ${extensionPath} --zip-source`)

expect(
distFileExists(
template.name,
BROWSERS[0],
`${template.name}-1.0-source.zip`
)
).toBeTruthy()
},
50000
)

it.each([DEFAULT_TEMPLATE])(
`builds and zips the source files of an extension created via "$name" template with a custom output name using the --zip-filename flag`,
async (template) => {
const extensionPath = path.join(__dirname, 'fixtures', template.name)

await extensionProgram(
`build ${extensionPath} --zip --zip-filename ${template.name}-nice`
)

expect(
distFileExists(template.name, BROWSERS[0], `${template.name}-nice.zip`)
).toBeTruthy()
},
50000
)
})
})
Loading
Loading