Skip to content

Commit

Permalink
♻️ Update package exports and refactor test helpers (#830)
Browse files Browse the repository at this point in the history
* ♻ Update @percy/env exports

✅ Refactor @percy/env test helper

* ♻ Update @percy/logger exports

✅ Refactor test helpers slightly

* ✅ Update test config

- Allow respying with jasmine spies
- Add generator spacing lint config for methods
- Clean up defunct babel plugin

* ♻ Update @percy/client exports

✅ Rename client test helper

* ♻ Update @percy/sdk-utils exports

✅ Fix test helper imports

* ♻ Update @percy/config exports

✅ Refactor test helpers to use full filesystem mocks

* ♻ Update @percy/core exports & imports

✅ Refactor test helpers and usage within tests

* ♻ Update @percy/cli-command exports & imports

✅ Reexport core test helpers for consuming packages

* ♻ Update @percy/cli-build exports

✅ Update test imports

* ♻ Update @percy/cli-config exports

🐛 Create parent directories when creating config files
🐛 Fix renaming extensionless cnofig files when migrating
✅ Update test imports and remove unnecessary helpers file

* ♻ Update @percy/cli-upload exports

♻ Replace globby with fast-glob
✅ Refactor tests to use new helpers

* ♻ Update @percy/cli exports & imports

✅ Refactor tests to use new helpers

* ♻ Update @percy/cli-snapshot exports

✅ Refactor tests to use new helpers
✅ Remove redundant default import test

* ♻ Update @percy/cli-exec exports & imports

✅ Refactor tests to use new helpers

* ➖ Remove quibble dev dependency

* 💚 Increment cache key for windows

* ✅ Correctly alias package exports during dev

* ♻ Update cli-command utils exports
  • Loading branch information
wwilsman authored Mar 17, 2022
1 parent f5f974c commit d1668f0
Show file tree
Hide file tree
Showing 106 changed files with 1,064 additions and 1,168 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rules:
- before: false
after: false
named: after
method: before
space-before-function-paren:
- error
- anonymous: never
Expand Down
1 change: 1 addition & 0 deletions .github/.cache-key
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/ \
_____________/_ __ \_____________
Times we have broken CI: 3
Times Windows has broken CI: 99+
5 changes: 1 addition & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ const base = {
node: '12'
}
}]
],
plugins: [
'@babel/proposal-class-properties'
]
}]
};
Expand All @@ -27,7 +24,7 @@ const development = {
cwd: __dirname,
alias: {
'^@percy/((?!dom)[^/]+)$': './packages/\\1/src',
'^@percy/(.+)/dist/(.+)$': './packages/\\1/src/\\2'
'^@percy/([^/]+)/((?!test).+)$': './packages/\\1/src/\\2'
}
}]
]
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@babel/cli": "^7.11.6",
"@babel/core": "^7.14.6",
"@babel/eslint-parser": "^7.14.7",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/preset-env": "^7.14.7",
"@babel/register": "^7.11.5",
"@rollup/plugin-alias": "^3.1.3",
Expand Down Expand Up @@ -53,7 +52,6 @@
"memfs": "^3.4.0",
"nock": "^13.1.1",
"nyc": "^15.1.0",
"quibble": "^0.6.8",
"rollup": "^2.53.2",
"tsd": "^0.19.0"
}
Expand Down
12 changes: 6 additions & 6 deletions packages/cli-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"publishConfig": {
"access": "public"
},
"main": "dist/index.js",
"files": [
"dist"
],
"engines": {
"node": ">=12"
},
"files": [
"./dist"
],
"main": "./dist/index.js",
"exports": "./dist/index.js",
"scripts": {
"build": "node ../../scripts/build",
"lint": "eslint --ignore-path ../../.gitignore .",
Expand All @@ -30,7 +31,6 @@
]
},
"dependencies": {
"@percy/cli-command": "1.0.0-beta.76",
"@percy/logger": "1.0.0-beta.76"
"@percy/cli-command": "1.0.0-beta.76"
}
}
6 changes: 2 additions & 4 deletions packages/cli-build/test/finalize.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import mockAPI from '@percy/client/test/helpers';
import logger from '@percy/logger/test/helpers';
import { logger, setupTest } from '@percy/cli-command/test/helpers';
import finalize from '../src/finalize';

describe('percy build:finalize', () => {
beforeEach(() => {
mockAPI.start();
logger.mock();
setupTest();
});

afterEach(() => {
Expand Down
32 changes: 15 additions & 17 deletions packages/cli-build/test/wait.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logger from '@percy/logger/test/helpers';
import mockAPI from '@percy/client/test/helpers';
import { logger, api, setupTest } from '@percy/cli-command/test/helpers';
import wait from '../src/wait';

describe('percy build:wait', () => {
Expand All @@ -19,8 +18,7 @@ describe('percy build:wait', () => {

beforeEach(() => {
process.env.PERCY_TOKEN = '<<PERCY_TOKEN>>';
mockAPI.start();
logger.mock({ isTTY: true });
setupTest({ loggerTTY: true });
});

afterEach(() => {
Expand Down Expand Up @@ -48,7 +46,7 @@ describe('percy build:wait', () => {
});

it('logs while recieving snapshots', async () => {
mockAPI
api
.reply('/builds/123', () => [200, build({
state: 'pending'
})])
Expand All @@ -66,7 +64,7 @@ describe('percy build:wait', () => {
});

it('logs while processing snapshots', async () => {
mockAPI
api
.reply('/builds/123', () => [200, build({
'total-comparisons-finished': 16
})])
Expand All @@ -91,7 +89,7 @@ describe('percy build:wait', () => {
});

it('logs found diffs when finished', async () => {
mockAPI.reply('/builds/123', () => [200, build({
api.reply('/builds/123', () => [200, build({
'total-comparisons-diff': 16,
state: 'finished'
})]);
Expand All @@ -106,7 +104,7 @@ describe('percy build:wait', () => {
});

it('errors and logs found diffs when finished', async () => {
mockAPI.reply('/builds/123', () => [200, build({
api.reply('/builds/123', () => [200, build({
'total-comparisons-diff': 16,
state: 'finished'
})]);
Expand All @@ -121,7 +119,7 @@ describe('percy build:wait', () => {
});

it('does not error when diffs are not found', async () => {
mockAPI.reply('/builds/123', () => [200, build({
api.reply('/builds/123', () => [200, build({
'total-comparisons-diff': 0,
state: 'finished'
})]);
Expand All @@ -136,7 +134,7 @@ describe('percy build:wait', () => {
});

it('errors and logs the build state when unrecognized', async () => {
mockAPI.reply('/builds/123', () => [200, build({ state: 'expired' })]);
api.reply('/builds/123', () => [200, build({ state: 'expired' })]);
await expectAsync(wait(['--build=123'])).toBeRejected();

expect(logger.stdout).toEqual([]);
Expand All @@ -146,7 +144,7 @@ describe('percy build:wait', () => {
});

it('stops waiting on process termination', async () => {
mockAPI.reply('/builds/123', () => [200, build()]);
api.reply('/builds/123', () => [200, build()]);

let waiting = wait(['--build=123']);

Expand All @@ -165,7 +163,7 @@ describe('percy build:wait', () => {

describe('failure messages', () => {
it('logs an error when there are no snapshots', async () => {
mockAPI.reply('/builds/123', () => [200, build({
api.reply('/builds/123', () => [200, build({
state: 'failed',
'failure-reason': 'render_timeout'
})]);
Expand All @@ -181,7 +179,7 @@ describe('percy build:wait', () => {
});

it('logs an error when there are no snapshots', async () => {
mockAPI.reply('/builds/123', () => [200, build({
api.reply('/builds/123', () => [200, build({
state: 'failed',
'failure-reason': 'no_snapshots'
})]);
Expand All @@ -196,7 +194,7 @@ describe('percy build:wait', () => {
});

it('logs an error when the build was not finalized', async () => {
mockAPI.reply('/builds/123', () => [200, build({
api.reply('/builds/123', () => [200, build({
state: 'failed',
'failure-reason': 'missing_finalize'
})]);
Expand All @@ -211,7 +209,7 @@ describe('percy build:wait', () => {
});

it('logs an error and exits when build is missing resources', async () => {
mockAPI.reply('/builds/123', () => [200, build({
api.reply('/builds/123', () => [200, build({
state: 'failed',
'failure-reason': 'missing_resources'
})]);
Expand All @@ -226,7 +224,7 @@ describe('percy build:wait', () => {
});

it('logs an error and exits when parallel builds are missing', async () => {
mockAPI.reply('/builds/123', () => [200, build({
api.reply('/builds/123', () => [200, build({
state: 'failed',
'failure-reason': 'missing_resources',
'failure-details': {
Expand All @@ -246,7 +244,7 @@ describe('percy build:wait', () => {
});

it('logs the failure reason and exits when the reason is unrecognized', async () => {
mockAPI.reply('/builds/123', () => [200, build({
api.reply('/builds/123', () => [200, build({
state: 'failed',
'failure-reason': 'unrecognized_reason'
})]);
Expand Down
15 changes: 10 additions & 5 deletions packages/cli-command/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@
"publishConfig": {
"access": "public"
},
"main": "dist/index.js",
"bin": {
"percy-cli-readme": "bin/readme"
},
"files": [
"dist"
"./dist"
],
"engines": {
"node": ">=12"
},
"bin": {
"percy-cli-readme": "./bin/readme"
},
"main": "./dist/index.js",
"exports": {
".": "./dist/index.js",
"./utils": "./dist/utils.js",
"./test/helpers": "./test/helpers.js"
},
"scripts": {
"build": "node ../../scripts/build",
"lint": "eslint --ignore-path ../../.gitignore .",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-command/src/command.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logger from '@percy/logger';
import PercyConfig from '@percy/config';
import { set, del } from '@percy/config/dist/utils';
import * as CoreConfig from '@percy/core/dist/config';
import { set, del } from '@percy/config/utils';
import * as CoreConfig from '@percy/core/config';
import * as builtInFlags from './flags';
import formatHelp from './help';
import parse from './parse';
Expand Down
3 changes: 3 additions & 0 deletions packages/cli-command/src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export { default, command } from './command';
export { legacyCommand, legacyFlags as flags } from './legacy';
// export common packages to avoid dependency resolution issues
export { default as PercyConfig } from '@percy/config';
export { default as logger } from '@percy/logger';
2 changes: 1 addition & 1 deletion packages/cli-command/src/legacy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { merge } from '@percy/config/utils';
import { command } from './command';
import { merge } from '@percy/config/dist/utils';

// Legacy flags for older commands that inadvertently import a newer @percy/cli-command
export const legacyFlags = {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-command/src/parse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logger from '@percy/logger';
import { camelcase } from '@percy/config/dist/normalize';
import { camelcase } from '@percy/config/utils';
import { flagUsage } from './help';

// Make it possible to identify parse errors.
Expand Down
2 changes: 2 additions & 0 deletions packages/cli-command/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '@percy/config/utils';
export * from '@percy/core/utils';
3 changes: 1 addition & 2 deletions packages/cli-command/test/command.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logger from '@percy/logger/test/helpers';
import dedent from '@percy/core/test/helpers/dedent';
import { logger, dedent } from './helpers';
import command from '../src';

describe('Command', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-command/test/flags.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logger from '@percy/logger/test/helpers';
import dedent from '@percy/core/test/helpers/dedent';
import { logger, dedent } from './helpers';
import command from '../src';

describe('Built-in flags:', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-command/test/help.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logger from '@percy/logger/test/helpers';
import dedent from '@percy/core/test/helpers/dedent';
import { logger, dedent } from './helpers';
import command from '../src';

describe('Help output', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/cli-command/test/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@percy/core/test/helpers';
3 changes: 1 addition & 2 deletions packages/cli-command/test/legacy.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logger from '@percy/logger/test/helpers';
import dedent from '@percy/core/test/helpers/dedent';
import { logger, dedent } from './helpers';
import { command, legacyCommand, flags } from '../src';

describe('Legacy support', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-command/test/parse.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logger from '@percy/logger/test/helpers';
import { logger } from './helpers';
import command from '../src';

describe('Option parsing', () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/cli-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"publishConfig": {
"access": "public"
},
"main": "dist/index.js",
"files": [
"dist"
],
"engines": {
"node": ">=12"
},
"files": [
"./dist"
],
"main": "dist/index.js",
"exports": "dist/index.js",
"scripts": {
"build": "node ../../scripts/build",
"lint": "eslint --ignore-path ../../.gitignore .",
Expand All @@ -30,7 +31,6 @@
]
},
"dependencies": {
"@percy/cli-command": "1.0.0-beta.76",
"@percy/config": "1.0.0-beta.76"
"@percy/cli-command": "1.0.0-beta.76"
}
}
7 changes: 4 additions & 3 deletions packages/cli-config/src/create.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from 'fs';
import path from 'path';
import command from '@percy/cli-command';
import command, {
PercyConfig
} from '@percy/cli-command';

const DEFAULT_FILES = {
rc: '.percyrc',
Expand Down Expand Up @@ -58,8 +60,6 @@ export const create = command('create', {
'$0 ./config/percy.yml'
]
}, async ({ flags, args, log, exit }) => {
let PercyConfig = await import('@percy/config');

// discern the filetype
let filetype = args.filepath
? path.extname(args.filepath).replace(/^./, '')
Expand All @@ -80,6 +80,7 @@ export const create = command('create', {

// write stringified default config options to the filepath
let format = ['rc', 'yaml', 'yml'].includes(filetype) ? 'yaml' : filetype;
fs.mkdirSync(path.dirname(filepath), { recursive: true });
fs.writeFileSync(filepath, PercyConfig.stringify(format));
log.info(`Created Percy config: ${filepath}`);
});
Expand Down
Loading

0 comments on commit d1668f0

Please sign in to comment.