mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 13:47:52 +00:00
Remove the use of CJS require() on test files
Change-type: patch
This commit is contained in:
parent
0339160a0b
commit
6efd24489f
@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import * as chai from 'chai';
|
||||
import chaiAsPromised = require('chai-as-promised');
|
||||
import * as chaiAsPromised from 'chai-as-promised';
|
||||
import * as ejs from 'ejs';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
@ -1,15 +1,15 @@
|
||||
import * as Bluebird from 'bluebird';
|
||||
import { expect } from 'chai';
|
||||
import rewire = require('rewire');
|
||||
import * as sinon from 'sinon';
|
||||
import * as url from 'url';
|
||||
import { getBalenaSdk } from '../../build/utils/lazy';
|
||||
import tokens from './tokens';
|
||||
|
||||
const utils = rewire('../../build/auth/utils');
|
||||
const balena = getBalenaSdk();
|
||||
|
||||
describe('Utils:', function () {
|
||||
describe('Utils:', async function () {
|
||||
const rewire = await import('rewire');
|
||||
const utils = rewire('../../build/auth/utils');
|
||||
describe('.getDashboardLoginURL()', function () {
|
||||
it('should eventually be a valid url', () =>
|
||||
utils
|
||||
|
@ -259,7 +259,7 @@ describe('balena build', function () {
|
||||
const fsModPath = 'fs';
|
||||
const fsMod = await import(fsModPath);
|
||||
const qemuModPath = '../../build/utils/qemu';
|
||||
const qemuMod = require(qemuModPath);
|
||||
const qemuMod = await import(qemuModPath);
|
||||
const qemuBinPath = await qemuMod.getQemuPath(arch);
|
||||
try {
|
||||
// patch fs.access and fs.stat to pretend that a copy of the Qemu binary
|
||||
|
3
tests/commands/env/envs.spec.ts
vendored
3
tests/commands/env/envs.spec.ts
vendored
@ -20,6 +20,7 @@ import { stripIndent } from '../../../build/utils/lazy';
|
||||
|
||||
import { BalenaAPIMock } from '../../nock/balena-api-mock';
|
||||
import { runCommand } from '../../helpers';
|
||||
import { randomBytes } from 'node:crypto';
|
||||
|
||||
describe('balena envs', function () {
|
||||
const appName = 'test';
|
||||
@ -32,7 +33,7 @@ describe('balena envs', function () {
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
// Random device UUID used to frustrate _.memoize() in utils/cloud.ts
|
||||
fullUUID = require('crypto').randomBytes(16).toString('hex');
|
||||
fullUUID = randomBytes(16).toString('hex');
|
||||
shortUUID = fullUUID.substring(0, 7);
|
||||
});
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { expect } from 'chai';
|
||||
import mock = require('mock-require');
|
||||
import * as mock from 'mock-require';
|
||||
import type { Server } from 'net';
|
||||
import { createServer } from 'net';
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
import * as settings from 'balena-settings-client';
|
||||
import { getStorage } from 'balena-settings-storage';
|
||||
import { expect } from 'chai';
|
||||
import mock = require('mock-require');
|
||||
import * as mock from 'mock-require';
|
||||
import * as semver from 'semver';
|
||||
import * as sinon from 'sinon';
|
||||
|
||||
|
@ -20,12 +20,12 @@ import * as _ from 'lodash';
|
||||
import { promises as fs } from 'fs';
|
||||
import * as path from 'path';
|
||||
import { PathUtils } from '@balena/compose/dist/multibuild';
|
||||
import rewire = require('rewire');
|
||||
import * as sinon from 'sinon';
|
||||
import { Readable } from 'stream';
|
||||
import * as tar from 'tar-stream';
|
||||
import { streamToBuffer } from 'tar-utils';
|
||||
import { URL } from 'url';
|
||||
import { diff } from 'deep-object-diff';
|
||||
|
||||
import { makeImageName } from '../build/utils/compose_ts';
|
||||
import { stripIndent } from '../build/utils/lazy';
|
||||
@ -101,8 +101,6 @@ export async function inspectTarStream(
|
||||
try {
|
||||
expect($expected).to.deep.equal(found);
|
||||
} catch (e) {
|
||||
const { diff } =
|
||||
require('deep-object-diff') as typeof import('deep-object-diff');
|
||||
const diffStr = JSON.stringify(
|
||||
diff($expected, found),
|
||||
(_k, v) => (v === undefined ? 'undefined' : v),
|
||||
@ -202,7 +200,7 @@ export async function testDockerBuildStream(o: {
|
||||
}
|
||||
}
|
||||
|
||||
resetDockerignoreCache();
|
||||
await resetDockerignoreCache();
|
||||
|
||||
const { exitCode, out, err } = await runCommand(o.commandLine);
|
||||
|
||||
@ -254,7 +252,7 @@ export async function testPushBuildStream(o: {
|
||||
inspectTarStream(buildRequestBody, o.expectedFiles, o.projectPath),
|
||||
});
|
||||
|
||||
resetDockerignoreCache();
|
||||
await resetDockerignoreCache();
|
||||
|
||||
const { out, err } = await runCommand(o.commandLine);
|
||||
|
||||
@ -262,7 +260,9 @@ export async function testPushBuildStream(o: {
|
||||
expect(cleanOutput(out, true)).to.include.members(expectedResponseLines);
|
||||
}
|
||||
|
||||
export function resetDockerignoreCache() {
|
||||
export async function resetDockerignoreCache() {
|
||||
const rewire = await import('rewire');
|
||||
|
||||
if (process.env.BALENA_CLI_TEST_TYPE !== 'source') {
|
||||
return;
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ import * as _ from 'lodash';
|
||||
import * as path from 'path';
|
||||
|
||||
import * as packageJSON from '../package.json';
|
||||
import { getNodeEngineVersionWarn } from '../build/utils/messages';
|
||||
import { warnify } from '../build/utils/messages';
|
||||
|
||||
const balenaExe = process.platform === 'win32' ? 'balena.exe' : 'balena';
|
||||
const standalonePath = path.resolve(__dirname, '..', 'build-bin', balenaExe);
|
||||
@ -41,7 +43,6 @@ function matchesNodeEngineVersionWarn(msg: string) {
|
||||
.map((l) => l.trim())
|
||||
.filter((l) => l);
|
||||
|
||||
const { getNodeEngineVersionWarn } = require('../build/utils/messages');
|
||||
let nodeEngineWarn: string = getNodeEngineVersionWarn(
|
||||
'x.y.z',
|
||||
packageJSON.engines.node,
|
||||
@ -179,8 +180,6 @@ async function runCommandInSubprocess(
|
||||
const msg = `
|
||||
Error (possibly expected) executing child CLI process "${standalonePath}"
|
||||
${$error}`;
|
||||
const { warnify } =
|
||||
require('../build/utils/messages') as typeof import('../build/utils/messages');
|
||||
console.error(warnify(msg, '[debug] '));
|
||||
}
|
||||
resolve();
|
||||
|
@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Bluebird = require('bluebird');
|
||||
import * as Bluebird from 'bluebird';
|
||||
import * as path from 'path';
|
||||
import * as zlib from 'zlib';
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
import * as nock from 'nock';
|
||||
import * as fs from 'fs';
|
||||
import { interceptorServerPort } from './proxy-server';
|
||||
|
||||
export interface ScopeOpts {
|
||||
optional?: boolean;
|
||||
@ -170,8 +171,6 @@ export class NockMock {
|
||||
}
|
||||
|
||||
protected handleUnexpectedRequest(req: any) {
|
||||
const { interceptorServerPort } =
|
||||
require('./proxy-server') as typeof import('./proxy-server');
|
||||
const o = req.options || {};
|
||||
const u = o.uri || {};
|
||||
const method = req.method;
|
||||
|
@ -55,6 +55,7 @@
|
||||
*/
|
||||
|
||||
import * as http from 'http';
|
||||
import * as httpProxy from 'http-proxy';
|
||||
|
||||
const proxyServers: http.Server[] = [];
|
||||
|
||||
@ -81,8 +82,6 @@ export async function createProxyServerOnce(): Promise<[number, number]> {
|
||||
}
|
||||
|
||||
async function createProxyServer(): Promise<[number, number]> {
|
||||
const httpProxy = require('http-proxy') as typeof import('http-proxy');
|
||||
|
||||
const interceptorPort = await createInterceptorServer();
|
||||
|
||||
const proxy = httpProxy.createProxyServer();
|
||||
|
@ -132,8 +132,8 @@ describeSS('LivepushManager::setupFilesystemWatcher', function () {
|
||||
await setupDockerignoreTestData({ cleanup: true });
|
||||
});
|
||||
|
||||
this.beforeEach(() => {
|
||||
resetDockerignoreCache();
|
||||
this.beforeEach(async () => {
|
||||
await resetDockerignoreCache();
|
||||
});
|
||||
|
||||
describe('for project no-docker-compose/basic', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user