diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..03a9cf57 --- /dev/null +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml new file mode 100644 index 00000000..ead4c856 --- /dev/null +++ b/.github/workflows/cli.yml @@ -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 diff --git a/.github/workflows/create.yml b/.github/workflows/create.yml index c685b841..868886cd 100644 --- a/.github/workflows/create.yml +++ b/.github/workflows/create.yml @@ -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 diff --git a/programs/cli/jest.config.js b/programs/cli/jest.config.js index 87c30aa4..758fa133 100644 --- a/programs/cli/jest.config.js +++ b/programs/cli/jest.config.js @@ -1,4 +1,4 @@ module.exports = { preset: 'ts-jest', - testEnvironment: 'node', + testEnvironment: 'node' } diff --git a/programs/cli/package.json b/programs/cli/package.json index d694228b..121d04d8 100644 --- a/programs/cli/package.json +++ b/programs/cli/package.json @@ -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", diff --git a/programs/cli/spec/build.spec.ts b/programs/cli/spec/build.spec.ts index 44c83a89..b7c3a55c 100644 --- a/programs/cli/spec/build.spec.ts +++ b/programs/cli/spec/build.spec.ts @@ -6,123 +6,71 @@ // ╚═════╝╚══════╝╚═╝ 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 ) @@ -130,66 +78,47 @@ describe('extension build', () => { 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 ) diff --git a/programs/cli/spec/cli.spec.ts b/programs/cli/spec/cli.spec.ts index bdb745c8..5dfe4616 100644 --- a/programs/cli/spec/cli.spec.ts +++ b/programs/cli/spec/cli.spec.ts @@ -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 () => { diff --git a/programs/cli/spec/create.spec.ts b/programs/cli/spec/create.spec.ts index 89f0ba41..e26521e1 100644 --- a/programs/cli/spec/create.spec.ts +++ b/programs/cli/spec/create.spec.ts @@ -9,7 +9,7 @@ import path from 'path' import { ALL_TEMPLATES, ALL_TEMPLATES_BUT_DEFAULT, - DEFAULT_TEMPLATE, + DEFAULT_TEMPLATE } from './fixtures/constants' import { extensionProgram, @@ -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 { @@ -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) { @@ -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) @@ -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()