Skip to content

Commit

Permalink
Add cli tests to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Jun 23, 2024
1 parent de87730 commit 6a73f8e
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 169 deletions.
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 command
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 command
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
2 changes: 1 addition & 1 deletion .github/workflows/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
run: yarn
- name: Run compiler
run: yarn compile
- name: Run `extenion create` command
- name: Run extenion create command
run: yarn test:create
2 changes: 1 addition & 1 deletion programs/cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testEnvironment: 'node'
}
4 changes: 3 additions & 1 deletion programs/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"compile": "yarn compile:readme-files && yarn compile:tailwind-config && yarn compile:stylelint-config &&yarn compile:cli",
"clean": "rm -rf dist",
"before:test": "./spec/fixtures/install-npm-deps-for-fixtures.sh",
"test": "npm run before:test && jest"
"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
173 changes: 51 additions & 122 deletions programs/cli/spec/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,190 +6,119 @@
// ╚═════╝╚══════╝╚═╝

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

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

describe('running built-in templates', () => {
it.each([DEFAULT_TEMPLATE])(
`builds the "%s" extension template`,
it.each(ALL_TEMPLATES)(
`builds an extension created via "$name" template`,
async (template) => {
const templatePath = path.join(__dirname, 'fixtures', template)

await extensionProgram(`build ${templatePath}`)

// For all: Expect template folder to exist
expect(fs.existsSync(templatePath)).toBeTruthy()
},
50000
)

it.each([CUSTOM_TEMPLATES])(
`builds an extension created via "%s" template`,
async (template) => {
const templatePath = path.join(__dirname, 'fixtures', template)
const templateDistPath = path.join(
__dirname,
'fixtures',
template,
'dist',
BROWSERS[0]
)

await extensionProgram(`build ${templatePath}`)

// Expect template folder to exist
expect(fs.existsSync(templateDistPath)).toBeTruthy()
const extensionPath = path.join(__dirname, 'fixtures', template.name)
await extensionProgram(`build ${extensionPath}`)

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

// Expect context ui files to exist
expect(
fs.existsSync(
path.join(templateDistPath, 'side_panel', 'default_path.css')
)
).toBeTruthy()
expect(
fs.existsSync(
path.join(templateDistPath, 'side_panel', 'default_path.html')
)
).toBeTruthy()
expect(
fs.existsSync(
path.join(templateDistPath, 'side_panel', 'default_path.css')
)
).toBeTruthy()
// TODO: cezaraugusto test ui context files output

expect(
fs.existsSync(path.join(templateDistPath, 'assets', 'chatgpt.png'))
).toBeTruthy()
expect(
fs.existsSync(path.join(templateDistPath, 'assets', 'extension.png'))
).toBeTruthy()
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([CUSTOM_TEMPLATES])(
`builds the "%s" extension template across all browsers`,
it.each(ALL_TEMPLATES)(
`builds the "$name" extension template across all browsers`,
async (template) => {
const templatePath = path.join(__dirname, 'fixtures', template)
const extensionPath = path.join(__dirname, 'fixtures', template.name)
// Firefox is skippeed because it can't handle service workers.
const [chrome, edge /*, firefox */] = BROWSERS
const chromeDistPath = path.join(
__dirname,
'fixtures',
template,
'dist',
chrome
)
const edgeDistPath = path.join(
__dirname,
'fixtures',
template,
'dist',
edge
)

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

expect(fs.existsSync(chromeDistPath)).toBeTruthy()
expect(fs.existsSync(edgeDistPath)).toBeTruthy()
expect(distFileExists(template.name, chrome)).toBeTruthy()
expect(distFileExists(template.name, edge)).toBeTruthy()
},
50000
)
})

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

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

// TODO
// 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 "%s" template`,
`builds and zips the distribution files of an extension created via "$name" template`,
async (template) => {
const templatePath = path.join(__dirname, 'fixtures', template)
const templateDistPath = path.join(
__dirname,
'fixtures',
template,
'dist',
BROWSERS[0],
`${template}-1.0.zip`
)
const extensionPath = path.join(__dirname, 'fixtures', template.name)

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

// Expect template folder to exist
expect(fs.existsSync(templateDistPath)).toBeTruthy()
expect(distFileExists(template.name, 'chrome')).toBeTruthy()
},
50000
)

it.each([DEFAULT_TEMPLATE])(
`builds and zips the source files of an extension created via "%s" template`,
`builds and zips the source files of an extension created via "$name" template`,
async (template) => {
const templatePath = path.join(__dirname, 'fixtures', template)
const templateDistPath = path.join(
__dirname,
'fixtures',
template,
'dist',
BROWSERS[0],
`${template}-1.0-source.zip`
)
const extensionPath = path.join(__dirname, 'fixtures', template.name)

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

// Expect template folder to exist
expect(fs.existsSync(templateDistPath)).toBeTruthy()
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 "%s" template with a custom output name using the --zip-filename flag`,
`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 templatePath = path.join(__dirname, 'fixtures', template)
const templateDistPath = path.join(
__dirname,
'fixtures',
template,
'dist',
BROWSERS[0],
`${template}-nice.zip`
)
const extensionPath = path.join(__dirname, 'fixtures', template.name)

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

// Expect template folder to exist
expect(fs.existsSync(templateDistPath)).toBeTruthy()
expect(
distFileExists(template.name, BROWSERS[0], `${template.name}-nice.zip`)
).toBeTruthy()
},
50000
)
Expand Down
3 changes: 1 addition & 2 deletions programs/cli/spec/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
// ╚██████╗███████╗██║
// ╚═════╝╚══════╝╚═╝


import extensionProgram from './fixtures/helpers'
import {extensionProgram} from './fixtures/helpers'

describe('CLI Commands', () => {
it('returns usage instructions if no command is provided', async () => {
Expand Down
54 changes: 12 additions & 42 deletions programs/cli/spec/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import path from 'path'
import {
ALL_TEMPLATES,
ALL_TEMPLATES_BUT_DEFAULT,
DEFAULT_TEMPLATE,
DEFAULT_TEMPLATE
} from './fixtures/constants'
import {
extensionProgram,
Expand All @@ -22,7 +22,7 @@ describe('extension create', () => {
await removeAllTemplateFolders()
})

it.skip('throws an error if target directory has conflicting files', async () => {
it('throws an error if target directory has conflicting files', async () => {
const templatePath = path.join(__dirname, '..', 'dist', 'init')

try {
Expand All @@ -37,7 +37,7 @@ describe('extension create', () => {
}
}, 60000)

it.skip('throws an error if no project name is provided', async () => {
it('throws an error if no project name is provided', async () => {
try {
await extensionProgram('create')
} catch (error: any) {
Expand All @@ -48,33 +48,8 @@ describe('extension create', () => {
}
}, 30000)

it.each([DEFAULT_TEMPLATE])(
'creates a new extension via "%s" template',
async (template) => {
const extensionPath = path.join(__dirname, '..', 'dist', template.name)

await extensionProgram(`create ${extensionPath}`)

// Expect folder to exist
expect(fileExists(template.name)).toBeTruthy()

// Expect .gitignore to exist
expect(fileExists(template.name, '.gitignore')).toBeTruthy()

// Expect README.md to exist
expect(fileExists(template.name, 'README.md')).toBeTruthy()

// Expect package.json to exist
expect(fileExists(template.name, 'package.json')).toBeTruthy()

// Expect manifest.json to exist
expect(fileExists(template.name, 'manifest.json')).toBeTruthy()
},
50000
)

describe('using the --template flag', () => {
it.each(ALL_TEMPLATES_BUT_DEFAULT)(
it.each(ALL_TEMPLATES)(
`creates the "$name" extension template`,
async (template) => {
const extensionPath = path.join(__dirname, '..', 'dist', template.name)
Expand Down Expand Up @@ -134,19 +109,14 @@ describe('extension create', () => {
})

// Expect images/icons/icon_16.png and expect images/icons/icon_16.png
expect(
fileExists(template.name, 'images/icons/icon_16.png')
).toBeTruthy()
expect(
fileExists(template.name, 'images/icons/icon_48.png')
).toBeTruthy()

// Expect images/[feature].png
// TODO: cezaraugusto think about how to have
// all frameworks have the a predictable image name
// expect(
// fileExists(template.name, `images/${template.name}.png`)
// ).toBeTruthy()
if (template.name !== 'init') {
expect(
fileExists(template.name, 'images/icons/icon_16.png')
).toBeTruthy()
expect(
fileExists(template.name, 'images/icons/icon_48.png')
).toBeTruthy()
}

// Expect manifest.json to exist
expect(fileExists(template.name, 'manifest.json')).toBeTruthy()
Expand Down

0 comments on commit 6a73f8e

Please sign in to comment.