mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-20 14:13:08 +00:00
e1e35eb83b
We are refactoring the supervisor test suite into unit tests (for algorithms an domain model tests) and integration tests (for interaction with out-of-process dependencies). This means the current test suite needs to be classified into these two categories, and fixed whenever possible. This commit moves the test suite under the `test/legacy` folder, this folder should be progressively migrated and eventually removed. Subsequent commits will begin to split these files into unit and integration whenever possible. Depends-on: #1996 Change-type: patch
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import * as chai from 'chai';
|
|
import * as chaiAsPromised from 'chai-as-promised';
|
|
import * as sinonChai from 'sinon-chai';
|
|
import * as chaiThings from 'chai-things';
|
|
import * as chaiLike from 'chai-like';
|
|
|
|
/**
|
|
* Mocha runs this EXACTLY ONCE before all tests to set up globals that
|
|
* are used among all test files, such as chai assertion plugins. See
|
|
* https://mochajs.org/#test-fixture-decision-tree-wizard-thing
|
|
*
|
|
* IMPORTANT: The functionality in this global fixture hook should not break any
|
|
* suite run in isolation, and it should be required by ALL test suites.
|
|
* If unsure whether to add to global fixtures, refer to the chart above.
|
|
* Also, avoid setting global mutable variables here.
|
|
*/
|
|
export const mochaGlobalSetup = function () {
|
|
console.log('Setting up global fixtures for tests...');
|
|
|
|
/* Setup chai assertion plugins */
|
|
chai.use(chaiAsPromised);
|
|
chai.use(sinonChai);
|
|
chai.use(chaiLike);
|
|
chai.use(chaiThings);
|
|
};
|
|
|
|
process.env.ROOT_MOUNTPOINT = './test/data';
|
|
process.env.BOOT_MOUNTPOINT = '/mnt/boot';
|
|
process.env.CONFIG_JSON_PATH = '/config.json';
|
|
process.env.CONFIG_MOUNT_POINT = './test/data/config.json';
|
|
process.env.DATABASE_PATH = './test/data/database.sqlite';
|
|
process.env.DATABASE_PATH_2 = './test/data/database2.sqlite';
|
|
process.env.DATABASE_PATH_3 = './test/data/database3.sqlite';
|
|
process.env.LED_FILE = './test/data/led_file';
|
|
|
|
import * as fs from 'fs';
|
|
|
|
// Make sure they are no database files left over from
|
|
// previous runs
|
|
try {
|
|
fs.unlinkSync(process.env.DATABASE_PATH);
|
|
} catch {
|
|
/* noop */
|
|
}
|
|
try {
|
|
fs.unlinkSync(process.env.DATABASE_PATH_2);
|
|
} catch {
|
|
/* noop */
|
|
}
|
|
try {
|
|
fs.unlinkSync(process.env.DATABASE_PATH_3);
|
|
} catch {
|
|
/* noop */
|
|
}
|
|
fs.writeFileSync(
|
|
'./test/data/config.json',
|
|
fs.readFileSync('./test/data/testconfig.json'),
|
|
);
|
|
|
|
import '~/test-lib/mocked-dbus';
|
|
import '~/test-lib/mocked-dockerode';
|
|
import '~/test-lib/mocked-iptables';
|