balena-cli/tests/utils/eol-conversion.spec.ts
Marios Balamatsias ac96616e4e osConfigure/localFlash: Add support for Node.js v14
* Replace old resin-image-fs with newer balena-image-fs
* package.json: Remove resin-image-fs package
* package: Install dependencies that work with node14
* Remove resin-image-fs typings
* Fix etcher-sdk related types
* local/flash: Add unmountOnSuccess, write, direct properties on flash
	Taken from https://github.com/balena-io-modules/etcher-sdk/blob/master/examples/multi-destination.ts
* tests/utils/eol-conversion: Remove ext2fs sample binary
	Specifically ext2fs/build/Release/bindings.node
	I removed it because the file doesn't exist
* tests/test-data/pkg: Add new expected warnings darwin/linux/windows
* os/configure: Remove windows check
* local/flash: Check if environment is WSL and show warning message
* Get tests to pass with certain Node v14 warning messages
* INSTALL-WINDOWS: Remove os configure warning

Improve push and logs support for Node.js v14 (bump 'net-keepalive')

Resolves: #2200
Resolves: #1990
Change-type: minor
Signed-off-by: Marios Balamatsias <mbalamatsias@gmail.com>
2021-03-31 01:15:47 +03:00

94 lines
2.7 KiB
TypeScript

/**
* @license
* Copyright 2020 Balena Ltd.
*
* 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 { promises as fs } from 'fs';
import * as path from 'path';
import {
convertEolInPlace,
detectEncoding,
} from '../../build/utils/eol-conversion';
describe('convertEolInPlace() function', function () {
it('should return expected values', () => {
// pairs of [given input, expected output]
const testVector = [
['', ''],
['\r', '\r'],
['\n', '\n'],
['\r\r', '\r\r'],
['\n\r', '\n\r'],
['\r\n', '\n'],
['\r\n\n', '\n\n'],
['\r\n\r', '\n\r'],
['\r\n\r\n', '\n\n'],
['\r\n\n\r', '\n\n\r'],
['abc\r\ndef\r\n', 'abc\ndef\n'],
['abc\r\ndef\n\r', 'abc\ndef\n\r'],
['abc\r\ndef\n', 'abc\ndef\n'],
['abc\r\ndef\r', 'abc\ndef\r'],
['abc\r\ndef', 'abc\ndef'],
['\r\ndef\r\n', '\ndef\n'],
['\rdef\r', '\rdef\r'],
];
const js = JSON.stringify;
for (const [input, expected] of testVector) {
const result = convertEolInPlace(Buffer.from(input));
const resultStr = result.toString();
const msg = `input=${js(input)} result=${js(resultStr)} expected=${js(
expected,
)}`;
expect(resultStr).to.equal(expected, msg);
}
});
});
describe('detectEncoding() function', function () {
it('should correctly detect the encoding of a few selected files', async () => {
const sampleBinary = [
'drivelist/build/Release/drivelist.node',
'@balena.io/usb/build/Release/usb_bindings.node',
'xxhash/build/Release/hash.node',
'mountutils/build/Release/MountUtils.node',
];
const sampleText = [
'node_modules/.bin/etcher-image-write',
'node_modules/.bin/mocha',
'node_modules/.bin/rimraf',
'node_modules/.bin/gulp',
'node_modules/.bin/coffeelint',
'node_modules/.bin/tsc',
'node_modules/.bin/balena-lint',
'node_modules/.bin/balena-preload',
'node_modules/.bin/catch-uncommitted',
];
for (const fname of sampleBinary) {
const buf = await fs.readFile(path.join('node_modules', fname));
const encoding = await detectEncoding(buf);
expect(encoding).to.equal('binary');
}
for (const fname of sampleText) {
const buf = await fs.readFile(fname);
const encoding = await detectEncoding(buf);
expect(encoding).to.equal('utf-8');
}
});
});