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

Replace chai with assert #34

Merged
merged 1 commit into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions packages/convert-svg-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
"tmp": "0.0.33"
},
"devDependencies": {
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"mocha": "^5.0.0",
"sinon": "^4.2.2"
},
Expand Down
16 changes: 9 additions & 7 deletions packages/convert-svg-core/test/API.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

'use strict';

const { expect } = require('chai');
const assert = require('assert');
const sinon = require('sinon');

const API = require('../src/API');
Expand Down Expand Up @@ -50,26 +50,28 @@ describe('[convert-svg-core] API', () => {
it('should return Converter instance using provider', () => {
const converter = api.createConverter();

expect(converter).to.be.an.instanceOf(Converter);
expect(converter.provider).to.equal(provider);
assert.ok(converter instanceof Converter);
assert.strictEqual(converter.provider, provider);
});

it('should never return same instance', () => {
expect(api.createConverter()).to.not.equal(api.createConverter());
assert.notStrictEqual(api.createConverter(), api.createConverter());
});
});

describe('#provider', () => {
it('should return provider', () => {
expect(api.provider).to.equal(provider);
assert.strictEqual(api.provider, provider);
});
});

describe('#version', () => {
it('should return provider version', () => {
provider.getVersion.returns('0.0.0');
const version = '0.0.0';

expect(api.version).to.equal('0.0.0');
provider.getVersion.returns(version);

assert.equal(api.version, version);
});
});
});
20 changes: 12 additions & 8 deletions packages/convert-svg-core/test/CLI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

'use strict';

const { expect } = require('chai');
const assert = require('assert');
const { EOL } = require('os');
const sinon = require('sinon');
const { Writable } = require('stream');
Expand Down Expand Up @@ -54,19 +54,23 @@ describe('[convert-svg-core] CLI', () => {
it('should write message to error stream', () => {
cli.error('foo');

expect(outputStream.write.callCount).to.equal(0);
expect(errorStream.write.callCount).to.equal(1);
expect(errorStream.write.args[0]).to.deep.equal([ `foo${EOL}` ]);
assert.equal(outputStream.write.callCount, 0);
assert.equal(errorStream.write.callCount, 1);
assert.deepEqual(errorStream.write.args, [
[ `foo${EOL}` ]
]);
});
});

describe('#output', () => {
it('should write message to output stream', () => {
cli.output('foo');

expect(errorStream.write.callCount).to.equal(0);
expect(outputStream.write.callCount).to.equal(1);
expect(outputStream.write.args[0]).to.deep.equal([ `foo${EOL}` ]);
assert.equal(errorStream.write.callCount, 0);
assert.equal(outputStream.write.callCount, 1);
assert.deepEqual(outputStream.write.args, [
[ `foo${EOL}` ]
]);
});
});

Expand All @@ -76,7 +80,7 @@ describe('[convert-svg-core] CLI', () => {

describe('#provider', () => {
it('should return provider', () => {
expect(cli.provider).to.equal(provider);
assert.strictEqual(cli.provider, provider);
});
});
});
35 changes: 20 additions & 15 deletions packages/convert-svg-core/test/Converter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@

'use strict';

const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const assert = require('assert');
const sinon = require('sinon');

const Converter = require('../src/Converter');
const Provider = require('../src/Provider');

chai.use(chaiAsPromised);

const { expect } = chai;

describe('[convert-svg-core] Converter', () => {
let converter;
let provider;
Expand All @@ -53,8 +48,13 @@ describe('[convert-svg-core] Converter', () => {
it('should thrown an error', async() => {
await converter.destroy();

await expect(converter.convert('<svg></svg>')).to.eventually.be.rejectedWith(Error,
'Converter has been destroyed. A new Converter must be created');
try {
await converter.convert('<svg></svg>');
// Should have thrown
assert.fail();
} catch (e) {
assert.equal(e.message, 'Converter has been destroyed. A new Converter must be created');
}
});
});
});
Expand All @@ -66,35 +66,40 @@ describe('[convert-svg-core] Converter', () => {
it('should thrown an error', async() => {
await converter.destroy();

await expect(converter.convertFile('foo.svg')).to.eventually.be.rejectedWith(Error,
'Converter has been destroyed. A new Converter must be created');
try {
await converter.convertFile('foo.svg');
// Should have thrown
assert.fail();
} catch (e) {
assert.equal(e.message, 'Converter has been destroyed. A new Converter must be created');
}
});
});
});

describe('#destroy', () => {
it('should destroy the converter', async() => {
expect(converter.destroyed).to.equal(false);
assert.equal(converter.destroyed, false);

await converter.destroy();

expect(converter.destroyed).to.equal(true);
assert.equal(converter.destroyed, true);
});
});

describe('#destroyed', () => {
it('should indicate whether converter has been destroyed', async() => {
expect(converter.destroyed).to.equal(false);
assert.equal(converter.destroyed, false);

await converter.destroy();

expect(converter.destroyed).to.equal(true);
assert.equal(converter.destroyed, true);
});
});

describe('#provider', () => {
it('should return provider', () => {
expect(converter.provider).to.equal(provider);
assert.strictEqual(converter.provider, provider);
});
});
});
14 changes: 9 additions & 5 deletions packages/convert-svg-core/test/Provider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

'use strict';

const { expect } = require('chai');
const assert = require('assert');

const Provider = require('../src/Provider');

Expand Down Expand Up @@ -53,8 +53,12 @@ describe('[convert-svg-core] Provider', () => {
it('should throw an error by default', () => {
const provider = new Provider();

expect(() => provider[methodName]()).to.throw(Error,
`Provider#${methodName} abstract method is not implemented`);
assert.throws(() => {
provider[methodName]();
}, (error) => {
return error instanceof Error &&
error.message === `Provider#${methodName} abstract method is not implemented`;
});
});
});
});
Expand All @@ -63,15 +67,15 @@ describe('[convert-svg-core] Provider', () => {
it('should return Provider#getType transformed into lower case by default', () => {
const provider = new TestProviderImpl();

expect(provider.getExtension()).to.equal('type');
assert.equal(provider.getExtension(), 'type');
});
});

describe('#getFormat', () => {
it('should return Provider#getType transformed into upper case by default', () => {
const provider = new TestProviderImpl();

expect(provider.getFormat()).to.equal('TYPE');
assert.equal(provider.getFormat(), 'TYPE');
});
});
});
10 changes: 5 additions & 5 deletions packages/convert-svg-core/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

'use strict';

const { expect } = require('chai');
const assert = require('assert');

const API = require('../src/API');
const CLI = require('../src/CLI');
Expand All @@ -33,25 +33,25 @@ const Provider = require('../src/Provider');
describe('[convert-svg-core] index', () => {
describe('.API', () => {
it('should be a reference to API constructor', () => {
expect(index.API).to.equal(API, 'Must be API constructor');
assert.strictEqual(index.API, API, 'Must be API constructor');
});
});

describe('.CLI', () => {
it('should be a reference to CLI constructor', () => {
expect(index.CLI).to.equal(CLI, 'Must be CLI constructor');
assert.strictEqual(index.CLI, CLI, 'Must be CLI constructor');
});
});

describe('.Converter', () => {
it('should be a reference to Converter constructor', () => {
expect(index.Converter).to.equal(Converter, 'Must be Converter constructor');
assert.strictEqual(index.Converter, Converter, 'Must be Converter constructor');
});
});

describe('.Provider', () => {
it('should be a reference to Provider constructor', () => {
expect(index.Provider).to.equal(Provider, 'Must be Provider constructor');
assert.strictEqual(index.Provider, Provider, 'Must be Provider constructor');
});
});
});
2 changes: 0 additions & 2 deletions packages/convert-svg-test-helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
"url": "https://github.com/NotNinja/convert-svg.git"
},
"dependencies": {
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"file-url": "^2.0.2",
"lodash.clonedeep": "^4.5.0",
"mocha": "^5.0.0",
Expand Down
38 changes: 23 additions & 15 deletions packages/convert-svg-test-helper/src/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

'use strict';

const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const assert = require('assert');
const cloneDeep = require('lodash.clonedeep');
const fileUrl = require('file-url');
const fs = require('fs');
Expand All @@ -34,9 +33,6 @@ const util = require('util');

const coreTests = require('./tests.json');

chai.use(chaiAsPromised);

const { expect } = chai;
const makeDirectory = util.promisify(fs.mkdir);
const readFile = util.promisify(fs.readFile);
const removeFile = util.promisify(rimraf);
Expand Down Expand Up @@ -167,8 +163,8 @@ class Helper {
});

afterEach(() => {
expect(api.createConverter.callCount).to.equal(1);
expect(converter.destroy.callCount).to.equal(1);
assert.equal(api.createConverter.callCount, 1);
assert.equal(converter.destroy.callCount, 1);
});

afterEach(() => {
Expand Down Expand Up @@ -214,13 +210,19 @@ class Helper {
const method = testAPI ? api.convertFile.bind(api) : converter.convertFile.bind(converter);

if (test.error) {
await expect(method(inputFilePath, options)).to.eventually.be.rejectedWith(Error, test.error);
try {
await method(inputFilePath, options);
// Should have thrown
assert.fail();
} catch (e) {
assert.equal(e.message, test.error);
}
} else {
const actualFilePath = await method(inputFilePath, options);
const actual = await readFile(outputFilePath);

expect(actualFilePath).to.equal(outputFilePath);
expect(actual).to.deep.equal(expected);
assert.equal(actualFilePath, outputFilePath);
assert.deepEqual(actual, expected);
}
});
});
Expand Down Expand Up @@ -252,8 +254,8 @@ class Helper {
});

afterEach(() => {
expect(api.createConverter.callCount).to.equal(1);
expect(converter.destroy.callCount).to.equal(1);
assert.equal(api.createConverter.callCount, 1);
assert.equal(converter.destroy.callCount, 1);
});

afterEach(() => {
Expand Down Expand Up @@ -299,11 +301,17 @@ class Helper {
const method = testAPI ? api.convert.bind(api) : converter.convert.bind(converter);

if (test.error) {
await expect(method(input, options)).to.eventually.be.rejectedWith(Error, test.error);
try {
await method(input, options);
// Should have thrown
assert.fail();
} catch (e) {
assert.equal(e.message, test.error);
}
} else {
const actual = await method(input, options);

expect(actual).to.deep.equal(expected);
assert.deepEqual(actual, expected);
}
});
});
Expand Down Expand Up @@ -333,7 +341,7 @@ class Helper {
const method = testAPI ? api.convert.bind(api) : converter.convert.bind(converter);
const actual = await method(input);

expect(actual).to.deep.equal(expected);
assert.deepEqual(actual, expected);
});
});
}
Expand Down
1 change: 0 additions & 1 deletion packages/convert-svg-to-jpeg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"convert-svg-core": "^0.3.3"
},
"devDependencies": {
"chai": "^4.1.2",
"convert-svg-test-helper": "^0.3.3",
"mocha": "^5.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/convert-svg-to-jpeg/test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"mocha": true
},
"rules": {
"no-undefined": "off",
"no-unused-expressions": "off"
}
}
Loading