Skip to content

Commit

Permalink
✅ Use jasmine for testing (#230)
Browse files Browse the repository at this point in the history
* ➕➖ Add jasmine and remove mocha, expect

* ✅ Migrate @percy/env tests to jasmine from mocha, expect

* ✅ Migrate @percy/client tests to jasmine from mocha, expect

* ✅ Migrate @percy/config tests to jasmine from mocha, expect

* ✅ Migrate @percy/dom tests to jasmine from mocha, expect

* ✅ Migrate @percy/logger tests to jasmine from mocha, expect

* ✅ Migrate @percy/sdk-utils tests to jasmine from mocha, expect

* ✅ Migrate @percy/core tests to jasmine from mocha, expect

* ✅ Migrate @percy/cli tests to jasmine from mocha, expect

* ✅ Migrate @percy/cli-command tests to jasmine from mocha, expect

* ✅ Migrate @percy/cli-build tests to jasmine from mocha, expect

* ✅ Migrate @percy/cli-config tests to jasmine from mocha, expect

* ✅ Migrate @percy/cli-snapshot tests to jasmine from mocha, expect

* ✅ Migrate @percy/cli-upload tests to jasmine from mocha, expect

* ✅ Migrate @percy/cli-exec tests to jasmine from mocha, expect

* 🐛 Handle unhandled close rejection in crash handler

This promise is not awaited on because this handler happens within a callback event, however the
close method may reject if it has already been called or if the browser has been killed.

* ✅ Fix @percy/core tests

Fix string matching windows path

Ignore racey code coverage

* ✅ Display test summary failed stacktraces

* ✅ Bump test timeout to 10s

For Windows

* 🔧 Genericize test script

* ✅ Use jasmine spies
  • Loading branch information
Wil Wilsman authored Mar 8, 2021
1 parent e0d09fe commit 0f871cf
Show file tree
Hide file tree
Showing 87 changed files with 590 additions and 1,088 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
"@babel/preset-env": "^7.11.5",
"@babel/register": "^7.11.5",
"@oclif/dev-cli": "^1.22.2",
"babel-plugin-module-resolver": "^4.0.0",
"babel-plugin-istanbul": "^6.0.0",
"babel-plugin-module-resolver": "^4.0.0",
"cross-env": "^7.0.2",
"eslint": "^7.9.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"expect": "^26.4.2",
"jasmine": "^3.6.4",
"jasmine-spec-reporter": "^6.0.0",
"lerna": "^4.0.0",
"mocha": "^8.1.3",
"nock": "^13.0.4",
"nyc": "^15.1.0",
"tsd": "^0.14.0"
Expand Down
5 changes: 1 addition & 4 deletions packages/cli-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
"lint": "eslint --ignore-path ../../.gitignore .",
"postbuild": "oclif-dev manifest",
"readme": "oclif-dev readme",
"test": "cross-env NODE_ENV=test mocha",
"test": "node ../../scripts/test",
"test:coverage": "nyc yarn test"
},
"publishConfig": {
"access": "public"
},
"mocha": {
"require": "../../scripts/babel-register"
},
"oclif": {
"bin": "percy",
"commands": "./dist/commands",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-build/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
env:
mocha: true
jasmine: true
4 changes: 1 addition & 3 deletions packages/cli-build/test/finalize.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect';
import mockAPI from '@percy/client/test/helper';
import logger from '@percy/logger/test/helper';
import { Finalize } from '../src/commands/build/finalize';
Expand Down Expand Up @@ -27,8 +26,7 @@ describe('percy build:finalize', () => {
it('logs an error when PERCY_PARALLEL_TOTAL is not -1', async () => {
process.env.PERCY_PARALLEL_TOTAL = '5';

await expect(Finalize.run([]))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Finalize.run([])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual([
Expand Down
52 changes: 21 additions & 31 deletions packages/cli-build/test/wait.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect';
import logger from '@percy/logger/test/helper';
import mockAPI from '@percy/client/test/helper';
import { Wait } from '../src/commands/build/wait';
Expand Down Expand Up @@ -41,8 +40,7 @@ describe('percy build:wait', () => {
});

it('logs an error and exits when required args are missing', async () => {
await expect(Wait.run([]))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Wait.run([])).toBeRejectedWithError('EEXIT: 1');
expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual([
'[percy] Error: Missing build ID or commit SHA\n'
Expand All @@ -62,7 +60,7 @@ describe('percy build:wait', () => {
await Wait.run(['--build=123', '--interval=50']);

expect(logger.stderr).toEqual([]);
expect(logger.stdout).toEqual(expect.arrayContaining([
expect(logger.stdout).toEqual(jasmine.arrayContaining([
'[percy] Recieving snapshots...'
]));
});
Expand All @@ -85,7 +83,7 @@ describe('percy build:wait', () => {
await Wait.run(['--build=123', '--interval=50']);

expect(logger.stderr).toEqual([]);
expect(logger.stdout).toEqual(expect.arrayContaining([
expect(logger.stdout).toEqual(jasmine.arrayContaining([
'[percy] Processing 18 snapshots - 16 of 72 comparisons finished...',
'[percy] Processing 18 snapshots - 32 of 72 comparisons finished...',
'[percy] Processing 18 snapshots - finishing up...'
Expand All @@ -101,7 +99,7 @@ describe('percy build:wait', () => {
await Wait.run(['--build=123']);

expect(logger.stderr).toEqual([]);
expect(logger.stdout).toEqual(expect.arrayContaining([
expect(logger.stdout).toEqual(jasmine.arrayContaining([
'[percy] Build #10 finished! https://percy.io/test/test/123\n',
'[percy] Found 16 changes\n'
]));
Expand All @@ -113,11 +111,10 @@ describe('percy build:wait', () => {
state: 'finished'
})]);

await expect(Wait.run(['--build=123', '-f']))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Wait.run(['--build=123', '-f'])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stderr).toEqual([]);
expect(logger.stdout).toEqual(expect.arrayContaining([
expect(logger.stdout).toEqual(jasmine.arrayContaining([
'[percy] Build #10 finished! https://percy.io/test/test/123\n',
'[percy] Found 16 changes\n'
]));
Expand All @@ -132,19 +129,18 @@ describe('percy build:wait', () => {
await Wait.run(['--build=123', '-f']);

expect(logger.stderr).toEqual([]);
expect(logger.stdout).toEqual(expect.arrayContaining([
expect(logger.stdout).toEqual(jasmine.arrayContaining([
'[percy] Build #10 finished! https://percy.io/test/test/123\n',
'[percy] Found 0 changes\n'
]));
});

it('exits and logs the build state when unrecognized', async () => {
mockAPI.reply('/builds/123', () => [200, build({ state: 'expired' })]);
await expect(Wait.run(['--build=123']))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Wait.run(['--build=123'])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual(expect.arrayContaining([
expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy] Build #10 is expired. https://percy.io/test/test/123\n'
]));
});
Expand All @@ -156,11 +152,10 @@ describe('percy build:wait', () => {
'failure-reason': 'render_timeout'
})]);

await expect(Wait.run(['--build=123']))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Wait.run(['--build=123'])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual(expect.arrayContaining([
expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy] Build #10 failed! https://percy.io/test/test/123\n',
'[percy] Some snapshots in this build took too long to render ' +
'even after multiple retries.\n'
Expand All @@ -173,11 +168,10 @@ describe('percy build:wait', () => {
'failure-reason': 'no_snapshots'
})]);

await expect(Wait.run(['--build=123']))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Wait.run(['--build=123'])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual(expect.arrayContaining([
expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy] Build #10 failed! https://percy.io/test/test/123\n',
'[percy] No snapshots were uploaded to this build.\n'
]));
Expand All @@ -189,11 +183,10 @@ describe('percy build:wait', () => {
'failure-reason': 'missing_finalize'
})]);

await expect(Wait.run(['--build=123']))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Wait.run(['--build=123'])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual(expect.arrayContaining([
expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy] Build #10 failed! https://percy.io/test/test/123\n',
'[percy] Failed to correctly finalize.\n'
]));
Expand All @@ -205,11 +198,10 @@ describe('percy build:wait', () => {
'failure-reason': 'missing_resources'
})]);

await expect(Wait.run(['--build=123']))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Wait.run(['--build=123'])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual(expect.arrayContaining([
expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy] Build #10 failed! https://percy.io/test/test/123\n',
'[percy] Some build or snapshot resources failed to correctly upload.\n'
]));
Expand All @@ -226,11 +218,10 @@ describe('percy build:wait', () => {
}
})]);

await expect(Wait.run(['--build=123']))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Wait.run(['--build=123'])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual(expect.arrayContaining([
expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy] Build #10 failed! https://percy.io/test/test/123\n',
'[percy] Only 3 of 4 parallelized build processes finished.\n'
]));
Expand All @@ -242,11 +233,10 @@ describe('percy build:wait', () => {
'failure-reason': 'unrecognized_reason'
})]);

await expect(Wait.run(['--build=123']))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Wait.run(['--build=123'])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual(expect.arrayContaining([
expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy] Build #10 failed! https://percy.io/test/test/123\n',
'[percy] Error: unrecognized_reason\n'
]));
Expand Down
5 changes: 1 addition & 4 deletions packages/cli-command/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
"scripts": {
"build": "cross-env NODE_ENV=production babel src --out-dir dist --root-mode upward",
"lint": "eslint --ignore-path ../../.gitignore .",
"test": "cross-env NODE_ENV=test mocha",
"test": "node ../../scripts/test",
"test:coverage": "nyc yarn test",
"test:types": "tsd"
},
"publishConfig": {
"access": "public"
},
"mocha": {
"require": "../../scripts/babel-register"
},
"dependencies": {
"@oclif/command": "^1.8.0",
"@oclif/config": "^1.17.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-command/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
env:
mocha: true
jasmine: true
11 changes: 4 additions & 7 deletions packages/cli-command/test/command.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import expect from 'expect';
import logger from '@percy/logger/test/helper';
import PercyConfig from '@percy/config';
import PercyCommand, { flags } from '../src';
Expand Down Expand Up @@ -73,8 +72,7 @@ describe('PercyCommand', () => {
test() { this.error('test error'); }
}

await expect(TestPercyCommandError.run([]))
.rejects.toThrow('EEXIT: 1');
await expectAsync(TestPercyCommandError.run([])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual([
Expand All @@ -87,8 +85,7 @@ describe('PercyCommand', () => {
test() { this.exit(1); }
}

await expect(TestPercyCommandExit.run([]))
.rejects.toThrow('EEXIT: 1');
await expectAsync(TestPercyCommandExit.run([])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual([]);
Expand Down Expand Up @@ -125,12 +122,12 @@ describe('PercyCommand', () => {
it('returns Percy config and parsed flags', async () => {
process.env.PERCY_TOKEN = '<<PERCY_TOKEN>>';

await expect(TestPercyCommand.run([
await expectAsync(TestPercyCommand.run([
'--allowed-hostname', '*.percy.io',
'--network-idle-timeout', '150',
'--disable-cache',
'foo', 'bar'
])).resolves.toBeUndefined();
])).toBeResolved();

expect(results[0].percyrc()).toEqual({
version: 2,
Expand Down
5 changes: 1 addition & 4 deletions packages/cli-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
"lint": "eslint --ignore-path ../../.gitignore .",
"postbuild": "oclif-dev manifest",
"readme": "oclif-dev readme",
"test": "cross-env NODE_ENV=test mocha",
"test": "node ../../scripts/test",
"test:coverage": "nyc yarn test"
},
"publishConfig": {
"access": "public"
},
"mocha": {
"require": "../../scripts/babel-register"
},
"oclif": {
"bin": "percy",
"commands": "./dist/commands",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-config/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
env:
mocha: true
jasmine: true
6 changes: 2 additions & 4 deletions packages/cli-config/test/create.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path';
import expect from 'expect';
import { logger, getMockConfig } from './helpers';
import { Create } from '../src/commands/config/create';
import PercyConfig from '@percy/config';
Expand Down Expand Up @@ -56,8 +55,7 @@ describe('percy config:create', () => {
});

it('logs an error and exits when the filetype is unsupported', async () => {
await expect(Create.run([path.join('.config', 'percy.config.php')]))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Create.run([path.join('.config', 'percy.config.php')])).toBeRejectedWithError('EEXIT: 1');
expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual(['[percy] Unsupported filetype: php\n']);
});
Expand All @@ -66,7 +64,7 @@ describe('percy config:create', () => {
await Create.run(['.percy.yml']);
logger.clear();

await expect(Create.run(['.percy.yml'])).rejects.toThrow('EEXIT: 1');
await expectAsync(Create.run(['.percy.yml'])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual(['[percy] Percy config already exists: .percy.yml\n']);
Expand Down
7 changes: 2 additions & 5 deletions packages/cli-config/test/migrate.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path';
import expect from 'expect';
import PercyConfig from '@percy/config';
import { logger, mockConfig, getMockConfig } from './helpers';
import { Migrate } from '../src/commands/config/migrate';
Expand Down Expand Up @@ -77,8 +76,7 @@ describe('percy config:migrate', () => {
});

it('errors and exits when a config cannot be found', async () => {
await expect(Migrate.run([path.join('.config', 'percy.yml')]))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Migrate.run([path.join('.config', 'percy.yml')])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual([
Expand All @@ -93,8 +91,7 @@ describe('percy config:migrate', () => {
throw new Error('test');
});

await expect(Migrate.run([filename]))
.rejects.toThrow('EEXIT: 1');
await expectAsync(Migrate.run([filename])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual([
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-config/test/validate.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path';
import expect from 'expect';
import { logger, mockConfig } from './helpers';
import { Validate } from '../src/commands/config/validate';
import PercyConfig from '@percy/config';
Expand Down Expand Up @@ -64,7 +63,7 @@ describe('percy config:validate', () => {

it('logs an error and exits for invalid or unkown config options', async () => {
mockConfig('.invalid.yml', 'version: 2\ntest:\n value: false\nbar: baz');
await expect(Validate.run(['.invalid.yml'])).rejects.toThrow('EEXIT: 1');
await expectAsync(Validate.run(['.invalid.yml'])).toBeRejectedWithError('EEXIT: 1');

expect(logger.stdout).toEqual([
'[percy] Found config file: .invalid.yml\n'
Expand Down
6 changes: 1 addition & 5 deletions packages/cli-exec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
"lint": "eslint --ignore-path ../../.gitignore .",
"postbuild": "oclif-dev manifest",
"readme": "oclif-dev readme",
"test": "cross-env NODE_ENV=test mocha",
"test": "node ../../scripts/test",
"test:coverage": "nyc yarn test"
},
"publishConfig": {
"access": "public"
},
"mocha": {
"require": "../../scripts/babel-register",
"timeout": 10000
},
"oclif": {
"bin": "percy",
"commands": "./dist/commands",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-exec/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
env:
mocha: true
jasmine: true
Loading

0 comments on commit 0f871cf

Please sign in to comment.