mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-27 00:37:18 +00:00
Convert units.spc.js to typescript
Change-type: patch
This commit is contained in:
parent
4c4171e7fb
commit
9ea57a7df1
4
Makefile
4
Makefile
@ -150,7 +150,7 @@ sass:
|
|||||||
node-sass lib/gui/app/scss/main.scss > lib/gui/css/main.css
|
node-sass lib/gui/app/scss/main.scss > lib/gui/css/main.css
|
||||||
|
|
||||||
lint-ts:
|
lint-ts:
|
||||||
resin-lint --typescript lib webpack.config.ts
|
resin-lint --typescript lib tests webpack.config.ts
|
||||||
|
|
||||||
lint-js:
|
lint-js:
|
||||||
eslint --ignore-pattern scripts/resin/**/*.js tests scripts
|
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
|
electron-mocha $(MOCHA_OPTIONS) --full-trace --no-sandbox --renderer tests/gui
|
||||||
|
|
||||||
test-sdk:
|
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
|
test: test-gui test-sdk test-spectron
|
||||||
|
|
||||||
|
12
npm-shrinkwrap.json
generated
12
npm-shrinkwrap.json
generated
@ -1116,6 +1116,12 @@
|
|||||||
"integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==",
|
"integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==",
|
||||||
"dev": true
|
"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": {
|
"@types/color": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/color/-/color-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/color/-/color-3.0.0.tgz",
|
||||||
@ -1216,6 +1222,12 @@
|
|||||||
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==",
|
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==",
|
||||||
"dev": true
|
"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": {
|
"@types/node": {
|
||||||
"version": "12.12.24",
|
"version": "12.12.24",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.24.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.24.tgz",
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "make lint test sanity-checks",
|
"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 .",
|
"start": "./node_modules/.bin/electron .",
|
||||||
"postshrinkwrap": "node ./scripts/clean-shrinkwrap.js",
|
"postshrinkwrap": "node ./scripts/clean-shrinkwrap.js",
|
||||||
"configure": "node-gyp configure",
|
"configure": "node-gyp configure",
|
||||||
@ -94,7 +94,9 @@
|
|||||||
"@babel/preset-env": "^7.6.0",
|
"@babel/preset-env": "^7.6.0",
|
||||||
"@babel/preset-react": "^7.0.0",
|
"@babel/preset-react": "^7.0.0",
|
||||||
"@types/bindings": "^1.3.0",
|
"@types/bindings": "^1.3.0",
|
||||||
|
"@types/chai": "^4.2.7",
|
||||||
"@types/mime-types": "^2.1.0",
|
"@types/mime-types": "^2.1.0",
|
||||||
|
"@types/mocha": "^5.2.7",
|
||||||
"@types/node": "^12.12.24",
|
"@types/node": "^12.12.24",
|
||||||
"@types/node-ipc": "^9.1.2",
|
"@types/node-ipc": "^9.1.2",
|
||||||
"@types/react-dom": "^16.8.4",
|
"@types/react-dom": "^16.8.4",
|
||||||
|
@ -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)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
59
tests/shared/units.spec.ts
Normal file
59
tests/shared/units.spec.ts
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user