diff --git a/Makefile b/Makefile index d95660e5..aa93ece5 100644 --- a/Makefile +++ b/Makefile @@ -150,7 +150,7 @@ sass: node-sass lib/gui/app/scss/main.scss > lib/gui/css/main.css lint-ts: - resin-lint --typescript lib webpack.config.ts + resin-lint --typescript lib tests webpack.config.ts lint-js: eslint --ignore-pattern scripts/resin/**/*.js tests scripts @@ -181,7 +181,7 @@ test-gui: electron-mocha $(MOCHA_OPTIONS) --full-trace --no-sandbox --renderer tests/gui test-sdk: - electron-mocha $(MOCHA_OPTIONS) --full-trace --no-sandbox tests/shared + electron-mocha $(MOCHA_OPTIONS) --full-trace --no-sandbox tests/shared/**/*.js tests/shared/**/*.ts test: test-gui test-sdk test-spectron diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 6abc5757..760cf687 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1116,6 +1116,12 @@ "integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==", "dev": true }, + "@types/chai": { + "version": "4.2.7", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.7.tgz", + "integrity": "sha512-luq8meHGYwvky0O7u0eQZdA7B4Wd9owUCqvbw2m3XCrCU8mplYOujMBbvyS547AxJkC+pGnd0Cm15eNxEUNU8g==", + "dev": true + }, "@types/color": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/color/-/color-3.0.0.tgz", @@ -1216,6 +1222,12 @@ "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==", "dev": true }, + "@types/mocha": { + "version": "5.2.7", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.7.tgz", + "integrity": "sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ==", + "dev": true + }, "@types/node": { "version": "12.12.24", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.24.tgz", diff --git a/package.json b/package.json index 18c5932a..d851cbd8 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "scripts": { "test": "make lint test sanity-checks", - "prettier": "prettier --config ./node_modules/resin-lint/config/.prettierrc --write \"lib/**/*.ts\" \"lib/**/*.tsx\" \"webpack.config.ts\"", + "prettier": "prettier --config ./node_modules/resin-lint/config/.prettierrc --write \"lib/**/*.ts\" \"lib/**/*.tsx\" \"tests/**/*.ts\" \"webpack.config.ts\"", "start": "./node_modules/.bin/electron .", "postshrinkwrap": "node ./scripts/clean-shrinkwrap.js", "configure": "node-gyp configure", @@ -94,7 +94,9 @@ "@babel/preset-env": "^7.6.0", "@babel/preset-react": "^7.0.0", "@types/bindings": "^1.3.0", + "@types/chai": "^4.2.7", "@types/mime-types": "^2.1.0", + "@types/mocha": "^5.2.7", "@types/node": "^12.12.24", "@types/node-ipc": "^9.1.2", "@types/react-dom": "^16.8.4", diff --git a/tests/shared/units.spec.js b/tests/shared/units.spec.js deleted file mode 100644 index 3d8ed652..00000000 --- a/tests/shared/units.spec.js +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2016 balena.io - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict' - -const m = require('mochainon') -// eslint-disable-next-line node/no-missing-require -const units = require('../../lib/shared/units') - -describe('Shared: Units', function () { - describe('.bytesToClosestUnit()', function () { - it('should convert bytes to terabytes', function () { - m.chai.expect(units.bytesToClosestUnit(1000000000000)).to.equal('1 TB') - m.chai.expect(units.bytesToClosestUnit(2987801405440)).to.equal('2.99 TB') - m.chai.expect(units.bytesToClosestUnit(999900000000000)).to.equal('1000 TB') - }) - - it('should convert bytes to gigabytes', function () { - m.chai.expect(units.bytesToClosestUnit(1000000000)).to.equal('1 GB') - m.chai.expect(units.bytesToClosestUnit(7801405440)).to.equal('7.8 GB') - m.chai.expect(units.bytesToClosestUnit(999900000000)).to.equal('1000 GB') - }) - - it('should convert bytes to megabytes', function () { - m.chai.expect(units.bytesToClosestUnit(1000000)).to.equal('1 MB') - m.chai.expect(units.bytesToClosestUnit(801405440)).to.equal('801 MB') - m.chai.expect(units.bytesToClosestUnit(999900000)).to.equal('1000 MB') - }) - - it('should convert bytes to kilobytes', function () { - m.chai.expect(units.bytesToClosestUnit(1000)).to.equal('1 kB') - m.chai.expect(units.bytesToClosestUnit(5440)).to.equal('5.44 kB') - m.chai.expect(units.bytesToClosestUnit(999900)).to.equal('1000 kB') - }) - - it('should keep bytes as bytes', function () { - m.chai.expect(units.bytesToClosestUnit(1)).to.equal('1 B') - m.chai.expect(units.bytesToClosestUnit(8)).to.equal('8 B') - m.chai.expect(units.bytesToClosestUnit(999)).to.equal('999 B') - }) - }) - - describe('.bytesToMegabytes()', function () { - it('should convert bytes to megabytes', function () { - m.chai.expect(units.bytesToMegabytes(1.2e+7)).to.equal(12) - m.chai.expect(units.bytesToMegabytes(332000)).to.equal(0.332) - }) - }) -}) diff --git a/tests/shared/units.spec.ts b/tests/shared/units.spec.ts new file mode 100644 index 00000000..4345617c --- /dev/null +++ b/tests/shared/units.spec.ts @@ -0,0 +1,59 @@ +/* + * Copyright 2016 balena.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect } from 'chai'; +import * as units from '../../lib/shared/units'; + +describe('Shared: Units', function() { + describe('.bytesToClosestUnit()', function() { + it('should convert bytes to terabytes', function() { + expect(units.bytesToClosestUnit(1000000000000)).to.equal('1 TB'); + expect(units.bytesToClosestUnit(2987801405440)).to.equal('2.99 TB'); + expect(units.bytesToClosestUnit(999900000000000)).to.equal('1000 TB'); + }); + + it('should convert bytes to gigabytes', function() { + expect(units.bytesToClosestUnit(1000000000)).to.equal('1 GB'); + expect(units.bytesToClosestUnit(7801405440)).to.equal('7.8 GB'); + expect(units.bytesToClosestUnit(999900000000)).to.equal('1000 GB'); + }); + + it('should convert bytes to megabytes', function() { + expect(units.bytesToClosestUnit(1000000)).to.equal('1 MB'); + expect(units.bytesToClosestUnit(801405440)).to.equal('801 MB'); + expect(units.bytesToClosestUnit(999900000)).to.equal('1000 MB'); + }); + + it('should convert bytes to kilobytes', function() { + expect(units.bytesToClosestUnit(1000)).to.equal('1 kB'); + expect(units.bytesToClosestUnit(5440)).to.equal('5.44 kB'); + expect(units.bytesToClosestUnit(999900)).to.equal('1000 kB'); + }); + + it('should keep bytes as bytes', function() { + expect(units.bytesToClosestUnit(1)).to.equal('1 B'); + expect(units.bytesToClosestUnit(8)).to.equal('8 B'); + expect(units.bytesToClosestUnit(999)).to.equal('999 B'); + }); + }); + + describe('.bytesToMegabytes()', function() { + it('should convert bytes to megabytes', function() { + expect(units.bytesToMegabytes(1.2e7)).to.equal(12); + expect(units.bytesToMegabytes(332000)).to.equal(0.332); + }); + }); +});