From 274503feb3f2f9cd5a8db551fd93b9cce8ae9b39 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Wed, 17 Aug 2022 15:26:49 -0400 Subject: [PATCH 1/5] Simplify test commands in package.json The supervisor used to perform tests both for the transpiled code (after tsc) and one for the typescript code (using ts-node/register/transpile-only). There is not really a reason for this and this added complexity to the test configuration. This used to make testing harder, as the built code didn't include source maps, meaning the tests did not point to the right code. Since we want to split tests in unit and integration tests as the next test improvement, it makes sense to simplify these commands before adding more complexity. Change-type: patch --- Dockerfile.template | 4 +- package.json | 276 +++++++++++++++++++++--------------------- test/.mocharc.fast.js | 12 -- test/.mocharc.js | 5 +- 4 files changed, 140 insertions(+), 157 deletions(-) delete mode 100644 test/.mocharc.fast.js diff --git a/Dockerfile.template b/Dockerfile.template index 8e2db25d..d213faac 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -96,13 +96,13 @@ COPY --from=build-base /usr/src/app/node_modules ./node_modules # Copy build files COPY build-utils ./build-utils -COPY webpack.config.js tsconfig.json tsconfig.release.json ./ +COPY webpack.config.js tsconfig.json tsconfig.release.json tsconfig.js.json ./ COPY src ./src COPY test ./test COPY typings ./typings # Run the tests -RUN npm run test-nolint +RUN npm run test ################################################### # Build the production package diff --git a/package.json b/package.json index 224175b2..fc35d0b0 100644 --- a/package.json +++ b/package.json @@ -1,143 +1,137 @@ { - "name": "balena-supervisor", - "description": "This is balena's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as the balena API informs it to.", - "version": "14.0.13", - "license": "Apache-2.0", - "repository": { - "type": "git", - "url": "https://github.com/balena-os/balena-supervisor.git" - }, - "scripts": { - "start": "./entry.sh", - "build": "npm run release && webpack", - "build:debug": "npm run release && npm run packagejson:copy", - "lint": "balena-lint -e ts -e js --typescript src/ test/ typings/ build-utils/ webpack.config.js && tsc --noEmit && tsc --noEmit --project tsconfig.js.json", - "test": "npm run clean && npm run test-nolint", - "posttest": "npm run lint", - "test-nolint": "npm run test:build && TEST=1 mocha --config test/.mocharc.js", - "test:build": "npm run test-build && npm run testitems:copy && npm run packagejson:copy", - "test:fast": "TEST=1 mocha --config test/.mocharc.fast.js", - "test:debug": "npm run test:build && TEST=1 mocha --inspect-brk --config test/.mocharc.js", - "prettify": "balena-lint -e ts -e js --typescript --fix src/ test/ typings/ build-utils/ webpack.config.js", - "test-build": "tsc --project tsconfig.json", - "release": "tsc --project tsconfig.release.json && mv build/src/* build", - "packagejson:copy": "cp package.json build/", - "testitems:copy": "cp -r test/data build/test/", - "sync": "ts-node --files sync/sync.ts", - "clean": "rimraf build" - }, - "private": true, - "dependencies": { - "@balena/happy-eyeballs": "0.0.6", - "dbus": "^1.0.7", - "mdns-resolver": "^1.0.0", - "semver": "^7.3.2", - "sinon": "^11.1.2", - "sqlite3": "^4.1.1", - "systeminformation": "^5.6.10" - }, - "engines": { - "node": "^12.16.2", - "npm": "^6.14.4" - }, - "devDependencies": { - "@balena/contrato": "^0.6.0", - "@balena/lint": "^5.1.0", - "@types/bluebird": "^3.5.32", - "@types/chai": "^4.2.16", - "@types/chai-as-promised": "^7.1.3", - "@types/chai-like": "^1.1.0", - "@types/chai-things": "0.0.34", - "@types/common-tags": "^1.8.0", - "@types/copy-webpack-plugin": "^6.0.0", - "@types/dbus": "^1.0.0", - "@types/dockerode": "^2.5.34", - "@types/event-stream": "^3.3.34", - "@types/express": "^4.17.3", - "@types/lodash": "^4.14.159", - "@types/memoizee": "^0.4.4", - "@types/mocha": "^8.2.2", - "@types/mock-fs": "^4.13.0", - "@types/morgan": "^1.9.0", - "@types/node": "^12.12.54", - "@types/request": "^2.48.5", - "@types/rewire": "^2.5.28", - "@types/rimraf": "^2.0.4", - "@types/rwlock": "^5.0.2", - "@types/semver": "^7.3.3", - "@types/shell-quote": "^1.7.0", - "@types/sinon": "^10.0.11", - "@types/sinon-chai": "^3.2.5", - "@types/supertest": "^2.0.11", - "@types/terser-webpack-plugin": "^3.0.0", - "@types/tmp": "^0.1.0", - "@types/webpack": "^4.41.21", - "@types/yargs": "^15.0.12", - "balena-register-device": "^7.2.0", - "blinking": "^0.0.4", - "bluebird": "^3.7.2", - "chai": "^4.3.4", - "chai-as-promised": "^7.1.1", - "chai-like": "^1.1.1", - "chai-things": "^0.2.0", - "chokidar": "^3.5.1", - "common-tags": "^1.8.0", - "copy-webpack-plugin": "^6.0.3", - "deep-object-diff": "^1.1.0", - "docker-delta": "^2.2.11", - "docker-progress": "^4.0.3", - "dockerode": "^2.5.8", - "duration-js": "^4.0.0", - "event-stream": "3.3.4", - "express": "^4.17.1", - "fork-ts-checker-webpack-plugin": "^5.1.0", - "fp-ts": "^2.8.1", - "husky": "^4.2.5", - "io-ts": "^2.2.10", - "io-ts-reporters": "^1.2.2", - "json-mask": "^0.3.9", - "knex": "^0.20.13", - "lint-staged": "^10.2.11", - "livepush": "^3.5.1", - "lodash": "^4.17.21", - "memoizee": "^0.4.14", - "mixpanel": "^0.10.3", - "mocha": "^8.3.2", - "mock-fs": "^4.14.0", - "morgan": "^1.10.0", - "network-checker": "^0.1.1", - "nock": "^13.1.2", - "nodemon": "^2.0.4", - "pinejs-client-request": "^7.2.1", - "pretty-ms": "^7.0.1", - "request": "^2.88.2", - "resin-docker-build": "^1.1.6", - "resumable-request": "^2.0.1", - "rewire": "^5.0.0", - "rimraf": "^2.7.1", - "rwlock": "^5.0.0", - "shell-quote": "^1.7.2", - "sinon-chai": "^3.6.0", - "strict-event-emitter-types": "^2.0.0", - "supertest": "^6.1.3", - "tar-stream": "^2.1.3", - "terser-webpack-plugin": "^4.1.0", - "tmp": "^0.1.0", - "ts-loader": "^7.0.5", - "ts-node": "^8.10.2", - "typed-error": "^3.2.1", - "typescript": "^4.2.4", - "webpack": "^4.44.1", - "webpack-cli": "^3.3.12", - "winston": "^3.3.3", - "yargs": "^15.4.1" - }, - "husky": { - "hooks": { - "pre-commit": "lint-staged" - } - }, - "versionist": { - "publishedAt": "2022-08-02T21:43:16.303Z" - } + "name": "balena-supervisor", + "description": "This is balena's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as the balena API informs it to.", + "version": "14.0.13", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/balena-os/balena-supervisor.git" + }, + "scripts": { + "start": "./entry.sh", + "build": "npm run clean && npm run release && webpack", + "lint": "balena-lint -e ts -e js --typescript src/ test/ typings/ build-utils/ webpack.config.js", + "test:build": "tsc --noEmit && tsc --noEmit --project tsconfig.js.json", + "test:node": "mocha --config test/.mocharc.js", + "test": "npm run lint && npm run test:build && npm run test:node", + "test:fast": "npm run test:build && npm run test:node", + "prettify": "balena-lint -e ts -e js --typescript --fix src/ test/ typings/ build-utils/ webpack.config.js", + "release": "tsc --project tsconfig.release.json && mv build/src/* build", + "sync": "ts-node --files sync/sync.ts", + "clean": "rimraf build" + }, + "private": true, + "dependencies": { + "@balena/happy-eyeballs": "0.0.6", + "dbus": "^1.0.7", + "mdns-resolver": "^1.0.0", + "semver": "^7.3.2", + "sinon": "^11.1.2", + "sqlite3": "^4.1.1", + "systeminformation": "^5.6.10" + }, + "engines": { + "node": "^12.16.2", + "npm": "^6.14.4" + }, + "devDependencies": { + "@balena/contrato": "^0.6.0", + "@balena/lint": "^5.1.0", + "@types/bluebird": "^3.5.32", + "@types/chai": "^4.2.16", + "@types/chai-as-promised": "^7.1.3", + "@types/chai-like": "^1.1.0", + "@types/chai-things": "0.0.34", + "@types/common-tags": "^1.8.0", + "@types/copy-webpack-plugin": "^6.0.0", + "@types/dbus": "^1.0.0", + "@types/dockerode": "^2.5.34", + "@types/event-stream": "^3.3.34", + "@types/express": "^4.17.3", + "@types/lodash": "^4.14.159", + "@types/memoizee": "^0.4.4", + "@types/mocha": "^8.2.2", + "@types/mock-fs": "^4.13.0", + "@types/morgan": "^1.9.0", + "@types/node": "^12.12.54", + "@types/request": "^2.48.5", + "@types/rewire": "^2.5.28", + "@types/rimraf": "^2.0.4", + "@types/rwlock": "^5.0.2", + "@types/semver": "^7.3.3", + "@types/shell-quote": "^1.7.0", + "@types/sinon": "^10.0.11", + "@types/sinon-chai": "^3.2.5", + "@types/supertest": "^2.0.11", + "@types/terser-webpack-plugin": "^3.0.0", + "@types/tmp": "^0.1.0", + "@types/webpack": "^4.41.21", + "@types/yargs": "^15.0.12", + "balena-register-device": "^7.2.0", + "blinking": "^0.0.4", + "bluebird": "^3.7.2", + "chai": "^4.3.4", + "chai-as-promised": "^7.1.1", + "chai-like": "^1.1.1", + "chai-things": "^0.2.0", + "chokidar": "^3.5.1", + "common-tags": "^1.8.0", + "copy-webpack-plugin": "^6.0.3", + "deep-object-diff": "^1.1.0", + "docker-delta": "^2.2.11", + "docker-progress": "^4.0.3", + "dockerode": "^2.5.8", + "duration-js": "^4.0.0", + "event-stream": "3.3.4", + "express": "^4.17.1", + "fork-ts-checker-webpack-plugin": "^5.1.0", + "fp-ts": "^2.8.1", + "husky": "^4.2.5", + "io-ts": "^2.2.10", + "io-ts-reporters": "^1.2.2", + "json-mask": "^0.3.9", + "knex": "^0.20.13", + "lint-staged": "^10.2.11", + "livepush": "^3.5.1", + "lodash": "^4.17.21", + "memoizee": "^0.4.14", + "mixpanel": "^0.10.3", + "mocha": "^8.3.2", + "mock-fs": "^4.14.0", + "morgan": "^1.10.0", + "network-checker": "^0.1.1", + "nock": "^13.1.2", + "nodemon": "^2.0.4", + "pinejs-client-request": "^7.2.1", + "pretty-ms": "^7.0.1", + "request": "^2.88.2", + "resin-docker-build": "^1.1.6", + "resumable-request": "^2.0.1", + "rewire": "^5.0.0", + "rimraf": "^2.7.1", + "rwlock": "^5.0.0", + "shell-quote": "^1.7.2", + "sinon-chai": "^3.6.0", + "strict-event-emitter-types": "^2.0.0", + "supertest": "^6.1.3", + "tar-stream": "^2.1.3", + "terser-webpack-plugin": "^4.1.0", + "tmp": "^0.1.0", + "ts-loader": "^7.0.5", + "ts-node": "^8.10.2", + "typed-error": "^3.2.1", + "typescript": "^4.2.4", + "webpack": "^4.44.1", + "webpack-cli": "^3.3.12", + "winston": "^3.3.3", + "yargs": "^15.4.1" + }, + "husky": { + "hooks": { + "pre-commit": "lint-staged" + } + }, + "versionist": { + "publishedAt": "2022-08-02T21:43:16.303Z" + } } diff --git a/test/.mocharc.fast.js b/test/.mocharc.fast.js deleted file mode 100644 index bb81f4a4..00000000 --- a/test/.mocharc.fast.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - bail: true, // Exit test script on first error - exit: true, // Force Mocha to exit after tests complete - recursive: true, // Look for tests in subdirectories - require: [ - // Files to execute before running suites - 'ts-node/register/transpile-only', - 'test/config/fixtures.ts', - ], - spec: ['test/**/*.spec.ts'], - timeout: '30000', -}; diff --git a/test/.mocharc.js b/test/.mocharc.js index 45196be2..bb81f4a4 100644 --- a/test/.mocharc.js +++ b/test/.mocharc.js @@ -4,8 +4,9 @@ module.exports = { recursive: true, // Look for tests in subdirectories require: [ // Files to execute before running suites - 'build/test/config/fixtures.js', + 'ts-node/register/transpile-only', + 'test/config/fixtures.ts', ], - spec: ['build/test/**/*.spec.js'], + spec: ['test/**/*.spec.ts'], timeout: '30000', }; From 1439ee30f2ed5e2ef2577e81669c053fdb6a1e25 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Wed, 17 Aug 2022 16:17:21 -0400 Subject: [PATCH 2/5] Move sinon to dev dependencies Sinon was added to the production dependencies by mistake in a previous build. This is a module only used for testing so this fixes that error. --- package-lock.json | 61 ++++++++++++++++++++++++++++------------------- package.json | 2 +- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index c58a729a..a5f13111 100644 --- a/package-lock.json +++ b/package-lock.json @@ -378,14 +378,16 @@ "version": "1.8.3", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz", "integrity": "sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ==", + "dev": true, "requires": { "type-detect": "4.0.8" } }, "@sinonjs/fake-timers": { - "version": "7.0.5", - "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-7.0.5.tgz", - "integrity": "sha512-fUt6b15bjV/VW93UP5opNXJxdwZSbK1EdiwnhN7XrQrcpaOhMJpZ/CjwFpM3THpxwA+YviBUJKSuEqKlCK5alw==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-7.1.2.tgz", + "integrity": "sha512-iQADsW4LBMISqZ6Ci1dupJL9pprqwcVFTcOsEmQOEhW+KLCVn/Y4Jrvg2k19fIHCp+iFprriYPTdRcQR8NbUPg==", + "dev": true, "requires": { "@sinonjs/commons": "^1.7.0" } @@ -394,6 +396,7 @@ "version": "6.1.1", "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-6.1.1.tgz", "integrity": "sha512-cZ7rKJTLiE7u7Wi/v9Hc2fs3Ucc3jrWeMgPHbbTCeVAB2S0wOBbYlkJVeNSL04i7fdhT8wIbDq1zhC/PXTD2SA==", + "dev": true, "requires": { "@sinonjs/commons": "^1.6.0", "lodash.get": "^4.4.2", @@ -401,9 +404,10 @@ } }, "@sinonjs/text-encoding": { - "version": "0.7.1", - "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz", - "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==" + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz", + "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", + "dev": true }, "@szmarczak/http-timer": { "version": "1.1.2", @@ -1723,7 +1727,8 @@ "dependencies": { "ansi-regex": { "version": "5.0.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", "dev": true }, "ansi-styles": { @@ -2434,7 +2439,8 @@ "dependencies": { "ansi-regex": { "version": "5.0.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", "dev": true }, "is-fullwidth-code-point": { @@ -3306,7 +3312,8 @@ "diff": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", - "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==" + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", + "dev": true }, "diffie-hellman": { "version": "5.0.3", @@ -6216,7 +6223,8 @@ "just-extend": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", - "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==" + "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==", + "dev": true }, "keyv": { "version": "3.1.0", @@ -6610,7 +6618,8 @@ "lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", - "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=" + "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==", + "dev": true }, "lodash.set": { "version": "4.3.2", @@ -7180,7 +7189,8 @@ "dependencies": { "ansi-regex": { "version": "5.0.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", "dev": true }, "ansi-styles": { @@ -7603,6 +7613,7 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.1.tgz", "integrity": "sha512-yr5kW2THW1AkxVmCnKEh4nbYkJdB3I7LUkiUgOvEkOp414mc2UMaHMA7pjq1nYowhdoJZGwEKGaQVbxfpWj10A==", + "dev": true, "requires": { "@sinonjs/commons": "^1.8.3", "@sinonjs/fake-timers": ">=5", @@ -7614,12 +7625,14 @@ "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", + "dev": true }, "path-to-regexp": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "dev": true, "requires": { "isarray": "0.0.1" } @@ -9286,6 +9299,7 @@ "version": "11.1.2", "resolved": "https://registry.npmjs.org/sinon/-/sinon-11.1.2.tgz", "integrity": "sha512-59237HChms4kg7/sXhiRcUzdSkKuydDeTiamT/jesUVHshBgL8XAmhgFo0GfK6RruMDM/iRSij1EybmMog9cJw==", + "dev": true, "requires": { "@sinonjs/commons": "^1.8.3", "@sinonjs/fake-timers": "^7.1.2", @@ -9295,23 +9309,17 @@ "supports-color": "^7.2.0" }, "dependencies": { - "@sinonjs/fake-timers": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-7.1.2.tgz", - "integrity": "sha512-iQADsW4LBMISqZ6Ci1dupJL9pprqwcVFTcOsEmQOEhW+KLCVn/Y4Jrvg2k19fIHCp+iFprriYPTdRcQR8NbUPg==", - "requires": { - "@sinonjs/commons": "^1.7.0" - } - }, "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, "requires": { "has-flag": "^4.0.0" } @@ -10572,7 +10580,8 @@ "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==" + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true }, "type-fest": { "version": "0.11.0", @@ -11616,7 +11625,8 @@ "dependencies": { "ansi-regex": { "version": "5.0.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", "dev": true }, "is-fullwidth-code-point": { @@ -11880,7 +11890,8 @@ "dependencies": { "ansi-regex": { "version": "5.0.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", "dev": true }, "cliui": { diff --git a/package.json b/package.json index fc35d0b0..2e2d05f3 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "dbus": "^1.0.7", "mdns-resolver": "^1.0.0", "semver": "^7.3.2", - "sinon": "^11.1.2", "sqlite3": "^4.1.1", "systeminformation": "^5.6.10" }, @@ -111,6 +110,7 @@ "rimraf": "^2.7.1", "rwlock": "^5.0.0", "shell-quote": "^1.7.2", + "sinon": "^11.1.2", "sinon-chai": "^3.6.0", "strict-event-emitter-types": "^2.0.0", "supertest": "^6.1.3", From 71eaa3327e7c5ff2d0895d4dadc0cda7a7ba7f1c Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Wed, 17 Aug 2022 18:31:16 -0400 Subject: [PATCH 3/5] Use tsconfig-paths for easier access to the source Currently, tests only can import source code modules through relative paths `../../`. This makes it very difficult to refactor and organize tests in folders as the paths change. [tsconfig-paths](https://www.npmjs.com/package/tsconfig-paths) allows to reference the source through an alias defined in the "paths" section of tsconfig.json --- package-lock.json | 31 +++++++++++++++++++++++++++++++ package.json | 1 + test/.mocharc.js | 1 + test/01-constants.spec.ts | 2 +- tsconfig.json | 9 ++++++++- 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index a5f13111..0b8f1302 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9760,6 +9760,12 @@ "ansi-regex": "^2.0.0" } }, + "strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", + "dev": true + }, "strip-final-newline": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", @@ -10446,6 +10452,31 @@ } } }, + "tsconfig-paths": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.1.0.tgz", + "integrity": "sha512-AHx4Euop/dXFC+Vx589alFba8QItjF+8hf8LtmuiCwHyI4rHXQtOOENaM8kvYf5fR0dRChy3wzWIZ9WbB7FWow==", + "dev": true, + "requires": { + "json5": "^2.2.1", + "minimist": "^1.2.6", + "strip-bom": "^3.0.0" + }, + "dependencies": { + "json5": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz", + "integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==", + "dev": true + }, + "minimist": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", + "dev": true + } + } + }, "tslib": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", diff --git a/package.json b/package.json index 2e2d05f3..868380aa 100644 --- a/package.json +++ b/package.json @@ -119,6 +119,7 @@ "tmp": "^0.1.0", "ts-loader": "^7.0.5", "ts-node": "^8.10.2", + "tsconfig-paths": "^4.1.0", "typed-error": "^3.2.1", "typescript": "^4.2.4", "webpack": "^4.44.1", diff --git a/test/.mocharc.js b/test/.mocharc.js index bb81f4a4..6f796a44 100644 --- a/test/.mocharc.js +++ b/test/.mocharc.js @@ -5,6 +5,7 @@ module.exports = { require: [ // Files to execute before running suites 'ts-node/register/transpile-only', + 'tsconfig-paths/register', 'test/config/fixtures.ts', ], spec: ['test/**/*.spec.ts'], diff --git a/test/01-constants.spec.ts b/test/01-constants.spec.ts index 2f81d78d..46516215 100644 --- a/test/01-constants.spec.ts +++ b/test/01-constants.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import constants = require('../src/lib/constants'); +import * as constants from '~/src-lib/constants'; describe('constants', function () { it('has the correct configJsonPathOnHost', () => diff --git a/tsconfig.json b/tsconfig.json index 1ec3cc9e..e84eb281 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "baseUrl": "./", "target": "ES2019", "module": "commonjs", "strict": true, @@ -11,7 +12,13 @@ "skipLibCheck": true, "lib": ["es2019"], "resolveJsonModule": true, - "allowJs": true + "allowJs": true, + "paths": { + "~/src/*": ["src/*"], + "~/lib/*": ["src/lib/*"], + "~/test-lib/*": ["test/lib/*"], + "~/test-data/*": ["test/data/*"] + } }, "include": ["src/**/*", "test/**/*", "typings/**/*.d.ts"] } From 382cdb0cfa1e3a3566bfa52b55cd1420ff241256 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Wed, 17 Aug 2022 19:35:08 -0400 Subject: [PATCH 4/5] Refactor test suite to use tsconfig paths This replaces all relative paths in the test suite (e.g `../src/compose/service.ts`) with the aliased path configured through tsconfig. This is a big change but it doesn't affect any functionality --- test/01-constants.spec.ts | 2 +- test/02-db.spec.ts | 20 ++++----- test/03-config.spec.ts | 10 ++--- test/05-device-state.spec.ts | 33 +++++++------- test/06-validation.spec.ts | 4 +- test/07-blink.spec.ts | 4 +- test/08-event-tracker.spec.ts | 32 +++++++------- test/09-network.spec.ts | 4 +- test/10-api-binder.spec.ts | 32 +++++++------- test/11-logger.spec.ts | 12 ++--- test/12-device-config.spec.ts | 24 +++++----- test/14-conversions.spec.ts | 2 +- test/15-ports.spec.ts | 6 +-- test/16-config-utils.spec.ts | 16 +++---- test/18-startup.spec.ts | 12 ++--- test/19-compose-utils.spec.ts | 2 +- test/21-supervisor-api.spec.ts | 16 +++---- test/22-local-mode.spec.ts | 8 ++-- test/23-contracts.spec.ts | 10 ++--- test/24-deltas.spec.ts | 2 +- test/25-journald.spec.ts | 4 +- test/27-extlinux-config.spec.ts | 4 +- test/28-db-format.spec.ts | 14 +++--- test/29-append-directive.spec.ts | 2 +- test/30-fdt-directive.spec.ts | 2 +- test/31-docker-utils.spec.ts | 4 +- test/33-extra-uenv-config.spec.ts | 6 +-- test/34-firewall.spec.ts | 18 ++++---- test/35-os-release.spec.ts | 2 +- test/37-odmdata-config.spec.ts | 6 +-- test/39-compose-commit.spec.ts | 4 +- test/40-target-state.spec.ts | 14 +++--- test/41-device-api-v1.spec.ts | 46 ++++++++++---------- test/42-device-api-v2.spec.ts | 30 ++++++------- test/43-splash-image.spec.ts | 6 +-- test/config/fixtures.ts | 6 +-- test/lib/application-state-mock.ts | 14 +++--- test/lib/db-helper.ts | 8 ++-- test/lib/mocked-database.ts | 4 +- test/lib/mocked-device-api.ts | 28 ++++++------ test/lib/mocked-iptables.ts | 4 +- test/lib/prepare.ts | 4 +- test/src/compose/app.spec.ts | 16 +++---- test/src/compose/application-manager.spec.ts | 26 +++++------ test/src/compose/images.spec.ts | 8 ++-- test/src/compose/network.spec.ts | 6 +-- test/src/compose/service.spec.ts | 32 +++++++------- test/src/compose/volume-manager.spec.ts | 8 ++-- test/src/compose/volume.spec.ts | 8 ++-- test/src/lib/backoff.spec.ts | 4 +- test/src/lib/fs-utils.spec.ts | 4 +- test/src/lib/json.spec.ts | 2 +- test/src/lib/legacy.spec.ts | 8 ++-- test/src/lib/lockfile.spec.ts | 6 +-- test/src/lib/system-info.spec.ts | 4 +- test/src/lib/update-lock.spec.ts | 12 ++--- 56 files changed, 311 insertions(+), 314 deletions(-) diff --git a/test/01-constants.spec.ts b/test/01-constants.spec.ts index 46516215..2a51fe0b 100644 --- a/test/01-constants.spec.ts +++ b/test/01-constants.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import * as constants from '~/src-lib/constants'; +import * as constants from '~/lib/constants'; describe('constants', function () { it('has the correct configJsonPathOnHost', () => diff --git a/test/02-db.spec.ts b/test/02-db.spec.ts index 794b7132..9cf1ded2 100644 --- a/test/02-db.spec.ts +++ b/test/02-db.spec.ts @@ -2,9 +2,9 @@ import * as Bluebird from 'bluebird'; import * as Knex from 'knex'; import { expect } from 'chai'; -import prepare = require('./lib/prepare'); -import * as constants from '../src/lib/constants'; -import { exists } from '../src/lib/fs-utils'; +import prepare = require('~/test-lib/prepare'); +import * as constants from '~/lib/constants'; +import { exists } from '~/lib/fs-utils'; async function createOldDatabase(path: string) { const knex = Knex({ @@ -49,16 +49,16 @@ describe('Database Migrations', () => { after(() => { // @ts-ignore constants.databasePath = process.env.DATABASE_PATH; - delete require.cache[require.resolve('../src/db')]; + delete require.cache[require.resolve('~/src/db')]; }); it('creates a database at the path passed on creation', async () => { const databasePath = process.env.DATABASE_PATH_2!; // @ts-ignore constants.databasePath = databasePath; - delete require.cache[require.resolve('../src/db')]; + delete require.cache[require.resolve('~/src/db')]; - const testDb = await import('../src/db'); + const testDb = await import('~/src/db'); await testDb.initialized; expect(await exists(databasePath)).to.be.true; }); @@ -69,8 +69,8 @@ describe('Database Migrations', () => { const knexForDB = await createOldDatabase(databasePath); // @ts-ignore constants.databasePath = databasePath; - delete require.cache[require.resolve('../src/db')]; - const testDb = await import('../src/db'); + delete require.cache[require.resolve('~/src/db')]; + const testDb = await import('~/src/db'); await testDb.initialized; await Bluebird.all([ expect(knexForDB.schema.hasColumn('app', 'appId')).to.eventually.be.true, @@ -97,11 +97,11 @@ describe('Database Migrations', () => { }); describe('Database', () => { - let db: typeof import('../src/db'); + let db: typeof import('~/src/db'); before(async () => { await prepare(); - db = await import('../src/db'); + db = await import('~/src/db'); }); it('initializes correctly, running the migrations', () => { return expect(db.initialized).to.be.fulfilled; diff --git a/test/03-config.spec.ts b/test/03-config.spec.ts index a156320f..897fec01 100644 --- a/test/03-config.spec.ts +++ b/test/03-config.spec.ts @@ -3,12 +3,12 @@ import { promises as fs } from 'fs'; import { SinonStub, stub } from 'sinon'; import { expect } from 'chai'; -import prepare = require('./lib/prepare'); -import * as conf from '../src/config'; +import prepare = require('~/test-lib/prepare'); +import * as conf from '~/src/config'; -import constants = require('../src/lib/constants'); -import { SchemaTypeKey } from '../src/config/schema-type'; -import { fnSchema } from '../src/config/functions'; +import constants = require('~/lib/constants'); +import { SchemaTypeKey } from '~/src/config/schema-type'; +import { fnSchema } from '~/src/config/functions'; describe('Config', () => { before(async () => { diff --git a/test/05-device-state.spec.ts b/test/05-device-state.spec.ts index 7becad52..fdf21bf6 100644 --- a/test/05-device-state.spec.ts +++ b/test/05-device-state.spec.ts @@ -1,25 +1,22 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; -import { StatusCodeError, UpdatesLockedError } from '../src/lib/errors'; -import * as dockerUtils from '../src/lib/docker-utils'; -import * as config from '../src/config'; -import * as imageManager from '../src/compose/images'; -import { ConfigTxt } from '../src/config/backends/config-txt'; -import * as deviceState from '../src/device-state'; -import * as deviceConfig from '../src/device-config'; -import { - loadTargetFromFile, - appsJsonBackup, -} from '../src/device-state/preload'; -import Service from '../src/compose/service'; -import { intialiseContractRequirements } from '../src/lib/contracts'; -import * as updateLock from '../src/lib/update-lock'; -import * as fsUtils from '../src/lib/fs-utils'; -import { TargetState } from '../src/types'; +import { StatusCodeError, UpdatesLockedError } from '~/lib/errors'; +import * as dockerUtils from '~/lib/docker-utils'; +import * as config from '~/src/config'; +import * as imageManager from '~/src/compose/images'; +import { ConfigTxt } from '~/src/config/backends/config-txt'; +import * as deviceState from '~/src/device-state'; +import * as deviceConfig from '~/src/device-config'; +import { loadTargetFromFile, appsJsonBackup } from '~/src/device-state/preload'; +import Service from '~/src/compose/service'; +import { intialiseContractRequirements } from '~/lib/contracts'; +import * as updateLock from '~/lib/update-lock'; +import * as fsUtils from '~/lib/fs-utils'; +import { TargetState } from '~/src/types'; -import * as dbHelper from './lib/db-helper'; -import log from '../src/lib/supervisor-console'; +import * as dbHelper from '~/test-lib/db-helper'; +import log from '~/lib/supervisor-console'; const mockedInitialConfig = { RESIN_SUPERVISOR_CONNECTIVITY_CHECK: 'true', diff --git a/test/06-validation.spec.ts b/test/06-validation.spec.ts index d2535fa7..12473028 100644 --- a/test/06-validation.spec.ts +++ b/test/06-validation.spec.ts @@ -8,9 +8,9 @@ import { DeviceName, NumericIdentifier, TargetApps, -} from '../src/types'; +} from '~/src/types'; -import * as validation from '../src/lib/validation'; +import * as validation from '~/lib/validation'; describe('validation', () => { describe('checkBooleanish', () => { diff --git a/test/07-blink.spec.ts b/test/07-blink.spec.ts index 9c50c492..def3c983 100644 --- a/test/07-blink.spec.ts +++ b/test/07-blink.spec.ts @@ -1,8 +1,8 @@ import { promises as fs } from 'fs'; import { expect } from 'chai'; -import blink = require('../src/lib/blink'); -import constants = require('../src/lib/constants'); +import blink = require('~/lib/blink'); +import constants = require('~/lib/constants'); describe('blink', () => { it('is a blink function', () => expect(blink).to.be.a('function')); diff --git a/test/08-event-tracker.spec.ts b/test/08-event-tracker.spec.ts index 298cedce..d7d46efd 100644 --- a/test/08-event-tracker.spec.ts +++ b/test/08-event-tracker.spec.ts @@ -2,16 +2,16 @@ import { SinonStub, stub, spy, SinonSpy } from 'sinon'; import { expect } from 'chai'; import * as mixpanel from 'mixpanel'; -import log from '../src/lib/supervisor-console'; -import supervisorVersion = require('../src/lib/supervisor-version'); -import * as config from '../src/config'; +import log from '~/lib/supervisor-console'; +import supervisorVersion = require('~/lib/supervisor-version'); +import * as config from '~/src/config'; describe('EventTracker', () => { let logEventStub: SinonStub; before(() => { logEventStub = stub(log, 'event'); - delete require.cache[require.resolve('../src/event-tracker')]; + delete require.cache[require.resolve('~/src/event-tracker')]; }); afterEach(() => { @@ -24,7 +24,7 @@ describe('EventTracker', () => { describe('Unmanaged', () => { let configStub: SinonStub; - let eventTracker: typeof import('../src/event-tracker'); + let eventTracker: typeof import('~/src/event-tracker'); before(async () => { configStub = stub(config, 'getMany').returns( @@ -36,13 +36,13 @@ describe('EventTracker', () => { }) as any, ); - eventTracker = await import('../src/event-tracker'); + eventTracker = await import('~/src/event-tracker'); }); after(() => { configStub.restore(); - delete require.cache[require.resolve('../src/event-tracker')]; + delete require.cache[require.resolve('~/src/event-tracker')]; }); it('initializes in unmanaged mode', () => { @@ -62,7 +62,7 @@ describe('EventTracker', () => { }); describe('Init', () => { - let eventTracker: typeof import('../src/event-tracker'); + let eventTracker: typeof import('~/src/event-tracker'); let configStub: SinonStub; let mixpanelSpy: SinonSpy; @@ -78,14 +78,14 @@ describe('EventTracker', () => { mixpanelSpy = spy(mixpanel, 'init'); - eventTracker = await import('../src/event-tracker'); + eventTracker = await import('~/src/event-tracker'); }); after(() => { configStub.restore(); mixpanelSpy.restore(); - delete require.cache[require.resolve('../src/event-tracker')]; + delete require.cache[require.resolve('~/src/event-tracker')]; }); it('initializes a mixpanel client when not in unmanaged mode', () => { @@ -100,7 +100,7 @@ describe('EventTracker', () => { }); describe('Managed', () => { - let eventTracker: typeof import('../src/event-tracker'); + let eventTracker: typeof import('~/src/event-tracker'); let configStub: SinonStub; let mixpanelStub: SinonStub; @@ -119,7 +119,7 @@ describe('EventTracker', () => { track: stub(), } as any); - eventTracker = await import('../src/event-tracker'); + eventTracker = await import('~/src/event-tracker'); await eventTracker.initialized; }); @@ -127,7 +127,7 @@ describe('EventTracker', () => { configStub.restore(); mixpanelStub.restore(); - delete require.cache[require.resolve('../src/event-tracker')]; + delete require.cache[require.resolve('~/src/event-tracker')]; }); it('calls the mixpanel client track function with the event, properties and uuid as distinct_id', async () => { @@ -189,21 +189,21 @@ describe('EventTracker', () => { }); describe('Rate limiting', () => { - let eventTracker: typeof import('../src/event-tracker'); + let eventTracker: typeof import('~/src/event-tracker'); let mixpanelStub: SinonStub; before(async () => { mixpanelStub = stub(mixpanel, 'init').returns({ track: stub(), } as any); - eventTracker = await import('../src/event-tracker'); + eventTracker = await import('~/src/event-tracker'); await eventTracker.initialized; }); after(() => { mixpanelStub.restore(); - delete require.cache[require.resolve('../src/event-tracker')]; + delete require.cache[require.resolve('~/src/event-tracker')]; }); it('should rate limit events of the same type', async () => { diff --git a/test/09-network.spec.ts b/test/09-network.spec.ts index 9bf4cf95..4b5fe5c1 100644 --- a/test/09-network.spec.ts +++ b/test/09-network.spec.ts @@ -3,8 +3,8 @@ import * as os from 'os'; import { stub, spy } from 'sinon'; import { expect } from 'chai'; -import Log from '../src/lib/supervisor-console'; -import * as network from '../src/network'; +import Log from '~/lib/supervisor-console'; +import * as network from '~/src/network'; describe('network', () => { describe('getIPAddresses', () => { diff --git a/test/10-api-binder.spec.ts b/test/10-api-binder.spec.ts index b9106708..7bef96d1 100644 --- a/test/10-api-binder.spec.ts +++ b/test/10-api-binder.spec.ts @@ -4,22 +4,22 @@ import { Server } from 'net'; import { SinonSpy, SinonStub, spy, stub } from 'sinon'; import { expect } from 'chai'; -import prepare = require('./lib/prepare'); -import * as config from '../src/config'; -import * as deviceState from '../src/device-state'; -import Log from '../src/lib/supervisor-console'; -import balenaAPI = require('./lib/mocked-balena-api'); -import { schema } from '../src/config/schema'; -import ConfigJsonConfigBackend from '../src/config/configJson'; -import * as TargetState from '../src/device-state/target-state'; -import * as ApiHelper from '../src/lib/api-helper'; -import supervisorVersion = require('../src/lib/supervisor-version'); -import * as eventTracker from '../src/event-tracker'; +import prepare = require('~/test-lib/prepare'); +import * as config from '~/src/config'; +import * as deviceState from '~/src/device-state'; +import Log from '~/lib/supervisor-console'; +import balenaAPI = require('~/test-lib/mocked-balena-api'); +import { schema } from '~/src/config/schema'; +import ConfigJsonConfigBackend from '~/src/config/configJson'; +import * as TargetState from '~/src/device-state/target-state'; +import * as ApiHelper from '~/lib/api-helper'; +import supervisorVersion = require('~/lib/supervisor-version'); +import * as eventTracker from '~/src/event-tracker'; import { TypedError } from 'typed-error'; -import { DeviceNotFoundError } from '../src/lib/errors'; +import { DeviceNotFoundError } from '~/lib/errors'; -let ApiBinder: typeof import('../src/api-binder'); +let ApiBinder: typeof import('~/src/api-binder'); class ExpectedError extends TypedError {} @@ -40,7 +40,7 @@ const initModels = async (obj: Dictionary, filename: string) => { }, } as any; - ApiBinder = await import('../src/api-binder'); + ApiBinder = await import('~/src/api-binder'); await ApiBinder.initialized; obj.apiBinder = ApiBinder; @@ -61,7 +61,7 @@ describe('ApiBinder', () => { let server: Server; before(async () => { - delete require.cache[require.resolve('../src/api-binder')]; + delete require.cache[require.resolve('~/src/api-binder')]; spy(balenaAPI.balenaBackend!, 'registerHandler'); server = balenaAPI.listen(3000); @@ -405,7 +405,7 @@ describe('ApiBinder', () => { }); it('fails when stateReportHealthy is false', async () => { - const currentState = await import('../src/api-binder/report'); + const currentState = await import('~/src/api-binder/report'); configStub.resolves({ unmanaged: false, diff --git a/test/11-logger.spec.ts b/test/11-logger.spec.ts index 9437f8da..6e0e4e96 100644 --- a/test/11-logger.spec.ts +++ b/test/11-logger.spec.ts @@ -5,11 +5,11 @@ import * as Promise from 'bluebird'; import { expect } from 'chai'; import * as sinon from 'sinon'; -import { ContainerLogs } from '../src/logging/container'; -import * as config from '../src/config'; +import { ContainerLogs } from '~/src/logging/container'; +import * as config from '~/src/config'; describe('Logger', function () { - let logger: typeof import('../src/logger'); + let logger: typeof import('~/src/logger'); let configStub: sinon.SinonStub; beforeEach(async function () { @@ -36,8 +36,8 @@ describe('Logger', function () { }), ); // delete the require cache for the logger module so we can force a refresh - delete require.cache[require.resolve('../src/logger')]; - logger = await import('../src/logger'); + delete require.cache[require.resolve('~/src/logger')]; + logger = await import('~/src/logger'); await logger.initialized; }); @@ -47,7 +47,7 @@ describe('Logger', function () { }); after(function () { - delete require.cache[require.resolve('../src/logger')]; + delete require.cache[require.resolve('~/src/logger')]; }); it('waits the grace period before sending any logs', function () { diff --git a/test/12-device-config.spec.ts b/test/12-device-config.spec.ts index 586c69c3..101bc004 100644 --- a/test/12-device-config.spec.ts +++ b/test/12-device-config.spec.ts @@ -4,19 +4,19 @@ import * as path from 'path'; import { SinonStub, stub, spy, SinonSpy, restore } from 'sinon'; import { expect } from 'chai'; -import * as deviceConfig from '../src/device-config'; -import * as fsUtils from '../src/lib/fs-utils'; -import * as logger from '../src/logger'; -import { Extlinux } from '../src/config/backends/extlinux'; -import { ConfigTxt } from '../src/config/backends/config-txt'; -import { Odmdata } from '../src/config/backends/odmdata'; -import { ConfigFs } from '../src/config/backends/config-fs'; -import { SplashImage } from '../src/config/backends/splash-image'; -import * as constants from '../src/lib/constants'; -import log from '../src/lib/supervisor-console'; -import { fnSchema } from '../src/config/functions'; +import * as deviceConfig from '~/src/device-config'; +import * as fsUtils from '~/lib/fs-utils'; +import * as logger from '~/src/logger'; +import { Extlinux } from '~/src/config/backends/extlinux'; +import { ConfigTxt } from '~/src/config/backends/config-txt'; +import { Odmdata } from '~/src/config/backends/odmdata'; +import { ConfigFs } from '~/src/config/backends/config-fs'; +import { SplashImage } from '~/src/config/backends/splash-image'; +import * as constants from '~/lib/constants'; +import log from '~/lib/supervisor-console'; +import { fnSchema } from '~/src/config/functions'; -import prepare = require('./lib/prepare'); +import prepare = require('~/test-lib/prepare'); import mock = require('mock-fs'); const extlinuxBackend = new Extlinux(); diff --git a/test/14-conversions.spec.ts b/test/14-conversions.spec.ts index dfd77496..a69941fa 100644 --- a/test/14-conversions.spec.ts +++ b/test/14-conversions.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import * as conversion from '../src/lib/conversions'; +import * as conversion from '~/lib/conversions'; describe('conversions', function () { describe('envArrayToObject', function () { diff --git a/test/15-ports.spec.ts b/test/15-ports.spec.ts index 23879a18..f9d67d79 100644 --- a/test/15-ports.spec.ts +++ b/test/15-ports.spec.ts @@ -1,4 +1,4 @@ -import { PortMap, PortRange } from '../src/compose/ports'; +import { PortMap, PortRange } from '~/src/compose/ports'; import { expect } from 'chai'; // Force cast `PortMap` as a public version so we can test it @@ -298,8 +298,8 @@ describe('Ports', function () { describe('Running container comparison', () => it('should not consider order when comparing current and target state', function () { - const portBindings = require('./data/ports/not-ascending/port-bindings.json'); - const compose = require('./data/ports/not-ascending/compose.json'); + const portBindings = require('~/test-data/ports/not-ascending/port-bindings.json'); + const compose = require('~/test-data/ports/not-ascending/compose.json'); const portMapsCurrent = PortMap.fromDockerOpts(portBindings); const portMapsTarget = PortMap.fromComposePorts(compose.ports); diff --git a/test/16-config-utils.spec.ts b/test/16-config-utils.spec.ts index 6bec1f51..57f0e7e8 100644 --- a/test/16-config-utils.spec.ts +++ b/test/16-config-utils.spec.ts @@ -2,14 +2,14 @@ import { stub } from 'sinon'; import * as _ from 'lodash'; import { expect } from 'chai'; -import * as config from '../src/config'; -import * as configUtils from '../src/config/utils'; -import { ExtraUEnv } from '../src/config/backends/extra-uEnv'; -import { Extlinux } from '../src/config/backends/extlinux'; -import { ConfigTxt } from '../src/config/backends/config-txt'; -import { ConfigFs } from '../src/config/backends/config-fs'; -import { SplashImage } from '../src/config/backends/splash-image'; -import { ConfigBackend } from '../src/config/backends/backend'; +import * as config from '~/src/config'; +import * as configUtils from '~/src/config/utils'; +import { ExtraUEnv } from '~/src/config/backends/extra-uEnv'; +import { Extlinux } from '~/src/config/backends/extlinux'; +import { ConfigTxt } from '~/src/config/backends/config-txt'; +import { ConfigFs } from '~/src/config/backends/config-fs'; +import { SplashImage } from '~/src/config/backends/splash-image'; +import { ConfigBackend } from '~/src/config/backends/backend'; describe('Config Utilities', () => { it('gets list of supported backends', async () => { diff --git a/test/18-startup.spec.ts b/test/18-startup.spec.ts index 6c0309c1..298552e4 100644 --- a/test/18-startup.spec.ts +++ b/test/18-startup.spec.ts @@ -2,12 +2,12 @@ import { SinonStub, stub } from 'sinon'; import { expect } from 'chai'; import * as _ from 'lodash'; -import * as apiBinder from '../src/api-binder'; -import * as applicationManager from '../src/compose/application-manager'; -import * as deviceState from '../src/device-state'; -import * as constants from '../src/lib/constants'; -import { docker } from '../src/lib/docker-utils'; -import { Supervisor } from '../src/supervisor'; +import * as apiBinder from '~/src/api-binder'; +import * as applicationManager from '~/src/compose/application-manager'; +import * as deviceState from '~/src/device-state'; +import * as constants from '~/src/lib/constants'; +import { docker } from '~/lib/docker-utils'; +import { Supervisor } from '~/src/supervisor'; describe('Startup', () => { let startStub: SinonStub; diff --git a/test/19-compose-utils.spec.ts b/test/19-compose-utils.spec.ts index 04f34f10..a43ae015 100644 --- a/test/19-compose-utils.spec.ts +++ b/test/19-compose-utils.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import * as ComposeUtils from '../src/compose/utils'; +import * as ComposeUtils from '~/src/compose/utils'; describe('Composition utilities', () => it('Should correctly camel case the configuration', function () { diff --git a/test/21-supervisor-api.spec.ts b/test/21-supervisor-api.spec.ts index 2c01d3b3..c28cf24d 100644 --- a/test/21-supervisor-api.spec.ts +++ b/test/21-supervisor-api.spec.ts @@ -2,14 +2,14 @@ import { expect } from 'chai'; import { spy } from 'sinon'; import * as supertest from 'supertest'; -import mockedAPI = require('./lib/mocked-device-api'); -import * as apiBinder from '../src/api-binder'; -import * as deviceState from '../src/device-state'; -import Log from '../src/lib/supervisor-console'; -import SupervisorAPI from '../src/supervisor-api'; -import * as apiKeys from '../src/lib/api-keys'; -import * as db from '../src/db'; -import { cloudApiKey } from '../src/lib/api-keys'; +import mockedAPI = require('~/test-lib/mocked-device-api'); +import * as apiBinder from '~/src/api-binder'; +import * as deviceState from '~/src/device-state'; +import Log from '~/lib/supervisor-console'; +import SupervisorAPI from '~/src/supervisor-api'; +import * as apiKeys from '~/lib/api-keys'; +import * as db from '~/src/db'; +import { cloudApiKey } from '~/lib/api-keys'; const mockedOptions = { listenPort: 54321, diff --git a/test/22-local-mode.spec.ts b/test/22-local-mode.spec.ts index 54ba3d88..710755ed 100644 --- a/test/22-local-mode.spec.ts +++ b/test/22-local-mode.spec.ts @@ -2,13 +2,13 @@ import { expect } from 'chai'; import * as Docker from 'dockerode'; import * as sinon from 'sinon'; -import * as db from '../src/db'; -import { docker } from '../src/lib/docker-utils'; +import * as db from '~/src/db'; +import { docker } from '~/lib/docker-utils'; import LocalModeManager, { EngineSnapshot, EngineSnapshotRecord, -} from '../src/local-mode'; -import ShortStackError from './lib/errors'; +} from '~/src/local-mode'; +import ShortStackError from '~/test-lib/errors'; describe('LocalModeManager', () => { let localMode: LocalModeManager; diff --git a/test/23-contracts.spec.ts b/test/23-contracts.spec.ts index c3ef7e19..9e9cf7ef 100644 --- a/test/23-contracts.spec.ts +++ b/test/23-contracts.spec.ts @@ -2,15 +2,15 @@ import { expect } from 'chai'; import { SinonStub, stub } from 'sinon'; import * as semver from 'semver'; -import * as constants from '../src/lib/constants'; +import * as constants from '~/lib/constants'; import { containerContractsFulfilled, intialiseContractRequirements, validateContract, -} from '../src/lib/contracts'; -import * as osRelease from '../src/lib/os-release'; -import supervisorVersion = require('../src/lib/supervisor-version'); -import * as fsUtils from '../src/lib/fs-utils'; +} from '~/lib/contracts'; +import * as osRelease from '~/lib/os-release'; +import supervisorVersion = require('~/lib/supervisor-version'); +import * as fsUtils from '~/lib/fs-utils'; describe('Container contracts', () => { before(() => { diff --git a/test/24-deltas.spec.ts b/test/24-deltas.spec.ts index 03044301..88dd42f6 100644 --- a/test/24-deltas.spec.ts +++ b/test/24-deltas.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import { stub } from 'sinon'; -import * as dockerUtils from '../src/lib/docker-utils'; +import * as dockerUtils from '~/lib/docker-utils'; describe('Deltas', () => { it('should correctly detect a V2 delta', async () => { diff --git a/test/25-journald.spec.ts b/test/25-journald.spec.ts index 79a00ddd..3517c629 100644 --- a/test/25-journald.spec.ts +++ b/test/25-journald.spec.ts @@ -1,8 +1,8 @@ import { SinonStub, stub } from 'sinon'; import { expect } from 'chai'; -import constants = require('../src/lib/constants'); -import { spawnJournalctl } from '../src/lib/journald'; +import constants = require('~/lib/constants'); +import { spawnJournalctl } from '~/lib/journald'; describe('journald', () => { let spawn: SinonStub; diff --git a/test/27-extlinux-config.spec.ts b/test/27-extlinux-config.spec.ts index 14419a76..30e2aea2 100644 --- a/test/27-extlinux-config.spec.ts +++ b/test/27-extlinux-config.spec.ts @@ -3,8 +3,8 @@ import { stripIndent } from 'common-tags'; import { SinonStub, stub } from 'sinon'; import { expect } from 'chai'; -import * as fsUtils from '../src/lib/fs-utils'; -import { Extlinux } from '../src/config/backends/extlinux'; +import * as fsUtils from '~/lib/fs-utils'; +import { Extlinux } from '~/src/config/backends/extlinux'; describe('Extlinux Configuration', () => { const backend = new Extlinux(); diff --git a/test/28-db-format.spec.ts b/test/28-db-format.spec.ts index ae643a35..f3e5038e 100644 --- a/test/28-db-format.spec.ts +++ b/test/28-db-format.spec.ts @@ -1,13 +1,13 @@ import { expect } from 'chai'; import { isRight } from 'fp-ts/lib/Either'; import * as sinon from 'sinon'; -import App from '../src/compose/app'; -import Network from '../src/compose/network'; -import * as config from '../src/config'; -import * as dbFormat from '../src/device-state/db-format'; -import log from '../src/lib/supervisor-console'; -import { TargetApps } from '../src/types/state'; -import * as dbHelper from './lib/db-helper'; +import App from '~/src/compose/app'; +import Network from '~/src/compose/network'; +import * as config from '~/src/config'; +import * as dbFormat from '~/src/device-state/db-format'; +import log from '~/lib/supervisor-console'; +import { TargetApps } from '~/src/types/state'; +import * as dbHelper from '~/test-lib/db-helper'; function getDefaultNetwork(appId: number) { return { diff --git a/test/29-append-directive.spec.ts b/test/29-append-directive.spec.ts index 2c53427d..872b6406 100644 --- a/test/29-append-directive.spec.ts +++ b/test/29-append-directive.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { AppendDirective } from '../src/config/backends/extlinux-file'; +import { AppendDirective } from '~/src/config/backends/extlinux-file'; describe('APPEND directive', () => { const supportedConfigValues = ['isolcpus']; diff --git a/test/30-fdt-directive.spec.ts b/test/30-fdt-directive.spec.ts index ac130056..ff547364 100644 --- a/test/30-fdt-directive.spec.ts +++ b/test/30-fdt-directive.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { FDTDirective } from '../src/config/backends/extlinux-file'; +import { FDTDirective } from '~/src/config/backends/extlinux-file'; describe('FDT directive', () => { const directive = new FDTDirective(); diff --git a/test/31-docker-utils.spec.ts b/test/31-docker-utils.spec.ts index adc155f9..0d3f0961 100644 --- a/test/31-docker-utils.spec.ts +++ b/test/31-docker-utils.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; -import { testWithData } from './lib/mocked-dockerode'; +import { testWithData } from '~/test-lib/mocked-dockerode'; -import * as dockerUtils from '../src/lib/docker-utils'; +import * as dockerUtils from '~/lib/docker-utils'; describe('Docker Utils', () => { describe('Supervisor Address', () => { diff --git a/test/33-extra-uenv-config.spec.ts b/test/33-extra-uenv-config.spec.ts index ebfeee00..082c363d 100644 --- a/test/33-extra-uenv-config.spec.ts +++ b/test/33-extra-uenv-config.spec.ts @@ -3,9 +3,9 @@ import { stripIndent } from 'common-tags'; import { SinonStub, spy, stub } from 'sinon'; import { expect } from 'chai'; -import * as fsUtils from '../src/lib/fs-utils'; -import Log from '../src/lib/supervisor-console'; -import { ExtraUEnv } from '../src/config/backends/extra-uEnv'; +import * as fsUtils from '~/lib/fs-utils'; +import Log from '~/lib/supervisor-console'; +import { ExtraUEnv } from '~/src/config/backends/extra-uEnv'; describe('extra_uEnv Configuration', () => { const backend = new ExtraUEnv(); diff --git a/test/34-firewall.spec.ts b/test/34-firewall.spec.ts index 6e01d160..a887d14f 100644 --- a/test/34-firewall.spec.ts +++ b/test/34-firewall.spec.ts @@ -2,18 +2,18 @@ import _ = require('lodash'); import { expect } from 'chai'; import * as Docker from 'dockerode'; -import { docker } from '../src/lib/docker-utils'; +import { docker } from '~/lib/docker-utils'; import * as sinon from 'sinon'; -import * as config from '../src/config'; -import * as firewall from '../src/lib/firewall'; -import * as logger from '../src/logger'; -import * as iptablesMock from './lib/mocked-iptables'; -import * as targetStateCache from '../src/device-state/target-state-cache'; +import * as config from '~/src/config'; +import * as firewall from '~/lib/firewall'; +import * as logger from '~/src/logger'; +import * as iptablesMock from '~/test-lib/mocked-iptables'; +import * as targetStateCache from '~/src/device-state/target-state-cache'; -import constants = require('../src/lib/constants'); -import { RuleAction, Rule } from '../src/lib/iptables'; -import { log } from '../src/lib/supervisor-console'; +import constants = require('~/lib/constants'); +import { RuleAction, Rule } from '~/lib/iptables'; +import { log } from '~/lib/supervisor-console'; describe('Host Firewall', function () { const dockerStubs: Dictionary = {}; diff --git a/test/35-os-release.spec.ts b/test/35-os-release.spec.ts index 15853dba..47a48d29 100644 --- a/test/35-os-release.spec.ts +++ b/test/35-os-release.spec.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import * as osRelease from '../src/lib/os-release'; +import * as osRelease from '~/lib/os-release'; const OS_RELEASE_PATH = 'test/data/etc/os-release-tx2'; diff --git a/test/37-odmdata-config.spec.ts b/test/37-odmdata-config.spec.ts index efa1e32c..c0b73f69 100644 --- a/test/37-odmdata-config.spec.ts +++ b/test/37-odmdata-config.spec.ts @@ -3,8 +3,8 @@ import { promises as fs } from 'fs'; import { resolve } from 'path'; import { expect } from 'chai'; -import Log from '../src/lib/supervisor-console'; -import { Odmdata } from '../src/config/backends/odmdata'; +import Log from '~/lib/supervisor-console'; +import { Odmdata } from '~/src/config/backends/odmdata'; describe('ODMDATA Configuration', () => { const backend = new Odmdata(); @@ -12,7 +12,7 @@ describe('ODMDATA Configuration', () => { let logErrorStub: SinonStub; // @ts-ignore accessing private vluae const previousConfigPath = Odmdata.bootConfigPath; - const testConfigPath = resolve(__dirname, 'data/boot0.img'); + const testConfigPath = resolve(process.cwd(), 'test/data/boot0.img'); before(() => { // @ts-ignore setting value of private variable diff --git a/test/39-compose-commit.spec.ts b/test/39-compose-commit.spec.ts index 3f6f7f0f..1252c4e7 100644 --- a/test/39-compose-commit.spec.ts +++ b/test/39-compose-commit.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; -import * as commitStore from '../src/compose/commit'; -import * as db from '../src/db'; +import * as commitStore from '~/src/compose/commit'; +import * as db from '~/src/db'; describe('compose/commit', () => { before(async () => await db.initialized); diff --git a/test/40-target-state.spec.ts b/test/40-target-state.spec.ts index a55f7020..778ffd06 100644 --- a/test/40-target-state.spec.ts +++ b/test/40-target-state.spec.ts @@ -4,14 +4,14 @@ import * as _ from 'lodash'; import rewire = require('rewire'); import { expect } from 'chai'; -import { sleep } from './lib/helpers'; -import * as TargetState from '../src/device-state/target-state'; -import Log from '../src/lib/supervisor-console'; -import * as request from '../src/lib/request'; -import * as deviceConfig from '../src/device-config'; -import { UpdatesLockedError } from '../src/lib/errors'; +import { sleep } from '~/test-lib/helpers'; +import * as TargetState from '~/src/device-state/target-state'; +import Log from '~/lib/supervisor-console'; +import * as request from '~/lib/request'; +import * as deviceConfig from '~/src/device-config'; +import { UpdatesLockedError } from '~/lib/errors'; -const deviceState = rewire('../src/device-state'); +const deviceState = rewire('~/src/device-state'); const stateEndpointBody = { local: { diff --git a/test/41-device-api-v1.spec.ts b/test/41-device-api-v1.spec.ts index 3e9f3f22..799eb9db 100644 --- a/test/41-device-api-v1.spec.ts +++ b/test/41-device-api-v1.spec.ts @@ -13,29 +13,29 @@ import * as supertest from 'supertest'; import * as path from 'path'; import { promises as fs } from 'fs'; -import { exists, unlinkAll } from '../src/lib/fs-utils'; -import * as appMock from './lib/application-state-mock'; -import * as mockedDockerode from './lib/mocked-dockerode'; -import mockedAPI = require('./lib/mocked-device-api'); -import sampleResponses = require('./data/device-api-responses.json'); -import * as config from '../src/config'; -import * as logger from '../src/logger'; -import SupervisorAPI from '../src/supervisor-api'; -import * as apiBinder from '../src/api-binder'; -import * as deviceState from '../src/device-state'; -import * as apiKeys from '../src/lib/api-keys'; -import * as dbus from '../src/lib/dbus'; -import * as updateLock from '../src/lib/update-lock'; -import * as TargetState from '../src/device-state/target-state'; -import * as targetStateCache from '../src/device-state/target-state-cache'; -import blink = require('../src/lib/blink'); -import constants = require('../src/lib/constants'); -import * as deviceAPI from '../src/device-api/common'; -import { UpdatesLockedError } from '../src/lib/errors'; -import { SchemaTypeKey } from '../src/config/schema-type'; -import log from '../src/lib/supervisor-console'; -import * as applicationManager from '../src/compose/application-manager'; -import App from '../src/compose/app'; +import { exists, unlinkAll } from '~/lib/fs-utils'; +import * as appMock from '~/test-lib/application-state-mock'; +import * as mockedDockerode from '~/test-lib/mocked-dockerode'; +import mockedAPI = require('~/test-lib/mocked-device-api'); +import sampleResponses = require('~/test-data/device-api-responses.json'); +import * as config from '~/src/config'; +import * as logger from '~/src/logger'; +import SupervisorAPI from '~/src/supervisor-api'; +import * as apiBinder from '~/src/api-binder'; +import * as deviceState from '~/src/device-state'; +import * as apiKeys from '~/lib/api-keys'; +import * as dbus from '~/lib/dbus'; +import * as updateLock from '~/lib/update-lock'; +import * as TargetState from '~/src/device-state/target-state'; +import * as targetStateCache from '~/src/device-state/target-state-cache'; +import blink = require('~/lib/blink'); +import constants = require('~/lib/constants'); +import * as deviceAPI from '~/src/device-api/common'; +import { UpdatesLockedError } from '~/lib/errors'; +import { SchemaTypeKey } from '~/src/config/schema-type'; +import log from '~/lib/supervisor-console'; +import * as applicationManager from '~/src/compose/application-manager'; +import App from '~/src/compose/app'; describe('SupervisorAPI [V1 Endpoints]', () => { let api: SupervisorAPI; diff --git a/test/42-device-api-v2.spec.ts b/test/42-device-api-v2.spec.ts index 6ba0d197..971e16a0 100644 --- a/test/42-device-api-v2.spec.ts +++ b/test/42-device-api-v2.spec.ts @@ -3,22 +3,22 @@ import { stub, SinonStub, spy, SinonSpy } from 'sinon'; import * as supertest from 'supertest'; import * as Bluebird from 'bluebird'; -import sampleResponses = require('./data/device-api-responses.json'); -import mockedAPI = require('./lib/mocked-device-api'); -import * as apiBinder from '../src/api-binder'; -import * as deviceState from '../src/device-state'; -import SupervisorAPI from '../src/supervisor-api'; -import * as serviceManager from '../src/compose/service-manager'; -import * as images from '../src/compose/images'; -import * as apiKeys from '../src/lib/api-keys'; -import * as config from '../src/config'; -import * as updateLock from '../src/lib/update-lock'; -import * as targetStateCache from '../src/device-state/target-state-cache'; -import * as mockedDockerode from './lib/mocked-dockerode'; -import * as applicationManager from '../src/compose/application-manager'; -import * as logger from '../src/logger'; +import sampleResponses = require('~/test-data/device-api-responses.json'); +import mockedAPI = require('~/test-lib/mocked-device-api'); +import * as apiBinder from '~/src/api-binder'; +import * as deviceState from '~/src/device-state'; +import SupervisorAPI from '~/src/supervisor-api'; +import * as serviceManager from '~/src/compose/service-manager'; +import * as images from '~/src/compose/images'; +import * as apiKeys from '~/lib/api-keys'; +import * as config from '~/src/config'; +import * as updateLock from '~/lib/update-lock'; +import * as targetStateCache from '~/src/device-state/target-state-cache'; +import * as mockedDockerode from '~/test-lib/mocked-dockerode'; +import * as applicationManager from '~/src/compose/application-manager'; +import * as logger from '~/src/logger'; -import { UpdatesLockedError } from '../src/lib/errors'; +import { UpdatesLockedError } from '~/lib/errors'; describe('SupervisorAPI [V2 Endpoints]', () => { let serviceManagerMock: SinonStub; diff --git a/test/43-splash-image.spec.ts b/test/43-splash-image.spec.ts index 3ec1668b..4d1419f5 100644 --- a/test/43-splash-image.spec.ts +++ b/test/43-splash-image.spec.ts @@ -2,9 +2,9 @@ import { promises as fs } from 'fs'; import { SinonStub, stub } from 'sinon'; import { expect } from 'chai'; -import * as fsUtils from '../src/lib/fs-utils'; -import { SplashImage } from '../src/config/backends/splash-image'; -import log from '../src/lib/supervisor-console'; +import * as fsUtils from '~/lib/fs-utils'; +import { SplashImage } from '~/src/config/backends/splash-image'; +import log from '~/lib/supervisor-console'; describe('Splash image configuration', () => { const backend = new SplashImage(); diff --git a/test/config/fixtures.ts b/test/config/fixtures.ts index 652c2687..83e20760 100644 --- a/test/config/fixtures.ts +++ b/test/config/fixtures.ts @@ -57,6 +57,6 @@ fs.writeFileSync( fs.readFileSync('./test/data/testconfig.json'), ); -import '../lib/mocked-dbus'; -import '../lib/mocked-dockerode'; -import '../lib/mocked-iptables'; +import '~/test-lib/mocked-dbus'; +import '~/test-lib/mocked-dockerode'; +import '~/test-lib/mocked-iptables'; diff --git a/test/lib/application-state-mock.ts b/test/lib/application-state-mock.ts index b63bad14..704a1a9c 100644 --- a/test/lib/application-state-mock.ts +++ b/test/lib/application-state-mock.ts @@ -1,11 +1,11 @@ -import * as networkManager from '../../src/compose/network-manager'; -import * as volumeManager from '../../src/compose/volume-manager'; -import * as serviceManager from '../../src/compose/service-manager'; -import * as imageManager from '../../src/compose/images'; +import * as networkManager from '~/src/compose/network-manager'; +import * as volumeManager from '~/src/compose/volume-manager'; +import * as serviceManager from '~/src/compose/service-manager'; +import * as imageManager from '~/src/compose/images'; -import Service from '../../src/compose/service'; -import Network from '../../src/compose/network'; -import Volume from '../../src/compose/volume'; +import Service from '~/src/compose/service'; +import Network from '~/src/compose/network'; +import Volume from '~/src/compose/volume'; const originalVolGetAll = volumeManager.getAll; const originalSvcGetAll = serviceManager.getAll; diff --git a/test/lib/db-helper.ts b/test/lib/db-helper.ts index 8282f99f..fbe4531a 100644 --- a/test/lib/db-helper.ts +++ b/test/lib/db-helper.ts @@ -1,5 +1,5 @@ -import * as constants from '../../src/lib/constants'; -import * as db from '../../src/db'; +import * as constants from '~/lib/constants'; +import * as db from '~/src/db'; import * as sinon from 'sinon'; // Creates a test database and returns a query builder @@ -13,7 +13,7 @@ export async function createDB() { constants.databasePath = process.env.DATABASE_PATH; // Cleanup the module cache in order to have it reloaded in the local context - delete require.cache[require.resolve('../../src/db')]; + delete require.cache[require.resolve('~/src/db')]; // Initialize the database module await db.initialized; @@ -76,7 +76,7 @@ export async function createDB() { // Cleanup the module cache in order to have it reloaded // correctly next time it's used - delete require.cache[require.resolve('../../src/db')]; + delete require.cache[require.resolve('~/src/db')]; }, }; } diff --git a/test/lib/mocked-database.ts b/test/lib/mocked-database.ts index 38fd59be..f5d694e5 100644 --- a/test/lib/mocked-database.ts +++ b/test/lib/mocked-database.ts @@ -2,8 +2,8 @@ import * as _ from 'lodash'; import { SinonStub, stub } from 'sinon'; import { QueryBuilder } from 'knex'; -import * as db from '../../src/db'; -import { Image } from '../../src/compose/images'; +import * as db from '~/src/db'; +import { Image } from '~/src/compose/images'; let modelStub: SinonStub | null = null; // MOCKED MODELS diff --git a/test/lib/mocked-device-api.ts b/test/lib/mocked-device-api.ts index 18ef91a8..07f2af0e 100644 --- a/test/lib/mocked-device-api.ts +++ b/test/lib/mocked-device-api.ts @@ -2,21 +2,21 @@ import * as _ from 'lodash'; import { Router } from 'express'; import rewire = require('rewire'); -import { unlinkAll } from '../../src/lib/fs-utils'; -import * as applicationManager from '../../src/compose/application-manager'; -import * as serviceManager from '../../src/compose/service-manager'; -import * as volumeManager from '../../src/compose/volume-manager'; -import * as commitStore from '../../src/compose/commit'; -import * as config from '../../src/config'; -import * as db from '../../src/db'; -import { createV1Api } from '../../src/device-api/v1'; -import { createV2Api } from '../../src/device-api/v2'; -import * as deviceState from '../../src/device-state'; -import SupervisorAPI from '../../src/supervisor-api'; -import { Service } from '../../src/compose/service'; -import { Image } from '../../src/compose/images'; +import { unlinkAll } from '~/lib/fs-utils'; +import * as applicationManager from '~/src/compose/application-manager'; +import * as serviceManager from '~/src/compose/service-manager'; +import * as volumeManager from '~/src/compose/volume-manager'; +import * as commitStore from '~/src/compose/commit'; +import * as config from '~/src/config'; +import * as db from '~/src/db'; +import { createV1Api } from '~/src/device-api/v1'; +import { createV2Api } from '~/src/device-api/v2'; +import * as deviceState from '~/src/device-state'; +import SupervisorAPI from '~/src/supervisor-api'; +import { Service } from '~/src/compose/service'; +import { Image } from '~/src/compose/images'; -const apiBinder = rewire('../../src/api-binder'); +const apiBinder = rewire('~/src/api-binder'); const DB_PATH = './test/data/supervisor-api.sqlite'; diff --git a/test/lib/mocked-iptables.ts b/test/lib/mocked-iptables.ts index 38c1bd4b..91fa24a8 100644 --- a/test/lib/mocked-iptables.ts +++ b/test/lib/mocked-iptables.ts @@ -3,8 +3,8 @@ import { expect } from 'chai'; import { stub } from 'sinon'; import * as childProcess from 'child_process'; -import * as firewall from '../../src/lib/firewall'; -import * as iptables from '../../src/lib/iptables'; +import * as firewall from '~/lib/firewall'; +import * as iptables from '~/lib/iptables'; import { EventEmitter } from 'events'; import { Writable } from 'stream'; diff --git a/test/lib/prepare.ts b/test/lib/prepare.ts index 93953de8..9e340f10 100644 --- a/test/lib/prepare.ts +++ b/test/lib/prepare.ts @@ -1,6 +1,6 @@ import * as fs from 'fs'; -import * as db from '../../src/db'; -import * as config from '../../src/config'; +import * as db from '~/src/db'; +import * as config from '~/src/config'; export = async function () { await db.initialized; diff --git a/test/src/compose/app.spec.ts b/test/src/compose/app.spec.ts index d6ce0cbd..7573d9f7 100644 --- a/test/src/compose/app.spec.ts +++ b/test/src/compose/app.spec.ts @@ -1,16 +1,16 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; -import App from '../../../src/compose/app'; +import App from '~/src/compose/app'; import { CompositionStep, CompositionStepAction, -} from '../../../src/compose/composition-steps'; -import { Image } from '../../../src/compose/images'; -import Network from '../../../src/compose/network'; -import Service from '../../../src/compose/service'; -import { ServiceComposeConfig } from '../../../src/compose/types/service'; -import Volume from '../../../src/compose/volume'; -import log from '../../../src/lib/supervisor-console'; +} from '~/src/compose/composition-steps'; +import { Image } from '~/src/compose/images'; +import Network from '~/src/compose/network'; +import Service from '~/src/compose/service'; +import { ServiceComposeConfig } from '~/src/compose/types/service'; +import Volume from '~/src/compose/volume'; +import log from '~/lib/supervisor-console'; const defaultContext = { localMode: false, diff --git a/test/src/compose/application-manager.spec.ts b/test/src/compose/application-manager.spec.ts index 2d734b99..33e7da23 100644 --- a/test/src/compose/application-manager.spec.ts +++ b/test/src/compose/application-manager.spec.ts @@ -1,20 +1,20 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; import { stub } from 'sinon'; -import App from '../../../src/compose/app'; -import * as applicationManager from '../../../src/compose/application-manager'; -import * as imageManager from '../../../src/compose/images'; -import * as serviceManager from '../../../src/compose/service-manager'; -import { Image } from '../../../src/compose/images'; -import Network from '../../../src/compose/network'; -import * as networkManager from '../../../src/compose/network-manager'; -import Service from '../../../src/compose/service'; -import { ServiceComposeConfig } from '../../../src/compose/types/service'; -import Volume from '../../../src/compose/volume'; -import log from '../../../src/lib/supervisor-console'; -import { InstancedAppState } from '../../../src/types/state'; +import App from '~/src/compose/app'; +import * as applicationManager from '~/src/compose/application-manager'; +import * as imageManager from '~/src/compose/images'; +import * as serviceManager from '~/src/compose/service-manager'; +import { Image } from '~/src/compose/images'; +import Network from '~/src/compose/network'; +import * as networkManager from '~/src/compose/network-manager'; +import Service from '~/src/compose/service'; +import { ServiceComposeConfig } from '~/src/compose/types/service'; +import Volume from '~/src/compose/volume'; +import log from '~/lib/supervisor-console'; +import { InstancedAppState } from '~/src/types/state'; -import * as dbHelper from '../../lib/db-helper'; +import * as dbHelper from '~/test-lib/db-helper'; const DEFAULT_NETWORK = Network.fromComposeObject('default', 1, 'appuuid', {}); diff --git a/test/src/compose/images.spec.ts b/test/src/compose/images.spec.ts index 6c738406..16e62bbf 100644 --- a/test/src/compose/images.spec.ts +++ b/test/src/compose/images.spec.ts @@ -1,11 +1,11 @@ import { expect } from 'chai'; -import * as imageManager from '../../../src/compose/images'; -import * as dbHelper from '../../lib/db-helper'; -import { createImage, withMockerode } from '../../lib/mockerode'; +import * as imageManager from '~/src/compose/images'; +import * as dbHelper from '~/test-lib/db-helper'; +import { createImage, withMockerode } from '~/test-lib/mockerode'; import * as sinon from 'sinon'; -import log from '../../../src/lib/supervisor-console'; +import log from '~/lib/supervisor-console'; // TODO: this code is duplicated in multiple tests // create a test module with all helper functions like this diff --git a/test/src/compose/network.spec.ts b/test/src/compose/network.spec.ts index 6944c9d9..cc510cce 100644 --- a/test/src/compose/network.spec.ts +++ b/test/src/compose/network.spec.ts @@ -1,11 +1,11 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; -import { Network } from '../../../src/compose/network'; +import { Network } from '~/src/compose/network'; import { NetworkInspectInfo } from 'dockerode'; -import { createNetwork, withMockerode } from '../../lib/mockerode'; +import { createNetwork, withMockerode } from '~/test-lib/mockerode'; -import { log } from '../../../src/lib/supervisor-console'; +import { log } from '~/lib/supervisor-console'; describe('compose/network', () => { describe('creating a network from a compose object', () => { diff --git a/test/src/compose/service.spec.ts b/test/src/compose/service.spec.ts index c85cc330..89ea7c45 100644 --- a/test/src/compose/service.spec.ts +++ b/test/src/compose/service.spec.ts @@ -2,31 +2,31 @@ import * as _ from 'lodash'; import * as sinon from 'sinon'; import { expect } from 'chai'; -import { createContainer } from '../../lib/mockerode'; +import { createContainer } from '~/test-lib/mockerode'; -import Service from '../../../src/compose/service'; -import Volume from '../../../src/compose/volume'; -import * as ServiceT from '../../../src/compose/types/service'; -import * as constants from '../../../src/lib/constants'; -import * as apiKeys from '../../../src/lib/api-keys'; +import Service from '~/src/compose/service'; +import Volume from '~/src/compose/volume'; +import * as ServiceT from '~/src/compose/types/service'; +import * as constants from '~/lib/constants'; +import * as apiKeys from '~/lib/api-keys'; -import log from '../../../src/lib/supervisor-console'; +import log from '~/lib/supervisor-console'; const configs = { simple: { - compose: require('../../data/docker-states/simple/compose.json'), - imageInfo: require('../../data/docker-states/simple/imageInfo.json'), - inspect: require('../../data/docker-states/simple/inspect.json'), + compose: require('~/test-data/docker-states/simple/compose.json'), + imageInfo: require('~/test-data/docker-states/simple/imageInfo.json'), + inspect: require('~/test-data/docker-states/simple/inspect.json'), }, entrypoint: { - compose: require('../../data/docker-states/entrypoint/compose.json'), - imageInfo: require('../../data/docker-states/entrypoint/imageInfo.json'), - inspect: require('../../data/docker-states/entrypoint/inspect.json'), + compose: require('~/test-data/docker-states/entrypoint/compose.json'), + imageInfo: require('~/test-data/docker-states/entrypoint/imageInfo.json'), + inspect: require('~/test-data/docker-states/entrypoint/inspect.json'), }, networkModeService: { - compose: require('../../data/docker-states/network-mode-service/compose.json'), - imageInfo: require('../../data/docker-states/network-mode-service/imageInfo.json'), - inspect: require('../../data/docker-states/network-mode-service/inspect.json'), + compose: require('~/test-data/docker-states/network-mode-service/compose.json'), + imageInfo: require('~/test-data/docker-states/network-mode-service/imageInfo.json'), + inspect: require('~/test-data/docker-states/network-mode-service/inspect.json'), }, }; diff --git a/test/src/compose/volume-manager.spec.ts b/test/src/compose/volume-manager.spec.ts index 1bc00c89..c4814018 100644 --- a/test/src/compose/volume-manager.spec.ts +++ b/test/src/compose/volume-manager.spec.ts @@ -5,10 +5,10 @@ import { createVolume, createContainer, withMockerode, -} from '../../lib/mockerode'; -import * as volumeManager from '../../../src/compose/volume-manager'; -import log from '../../../src/lib/supervisor-console'; -import Volume from '../../../src/compose/volume'; +} from '~/test-lib/mockerode'; +import * as volumeManager from '~/src/compose/volume-manager'; +import log from '~/lib/supervisor-console'; +import Volume from '~/src/compose/volume'; describe('compose/volume-manager', () => { describe('Retrieving volumes from the engine', () => { diff --git a/test/src/compose/volume.spec.ts b/test/src/compose/volume.spec.ts index 5dc443a8..6ae3abc6 100644 --- a/test/src/compose/volume.spec.ts +++ b/test/src/compose/volume.spec.ts @@ -1,10 +1,10 @@ import { expect } from 'chai'; import { SinonStub, stub } from 'sinon'; -import Volume from '../../../src/compose/volume'; -import * as logTypes from '../../../src/lib/log-types'; -import * as logger from '../../../src/logger'; +import Volume from '~/src/compose/volume'; +import * as logTypes from '~/lib/log-types'; +import * as logger from '~/src/logger'; -import { createVolume, withMockerode } from '../../lib/mockerode'; +import { createVolume, withMockerode } from '~/test-lib/mockerode'; describe('compose/volume', () => { describe('creating a volume from a compose object', () => { diff --git a/test/src/lib/backoff.spec.ts b/test/src/lib/backoff.spec.ts index dd680657..d114de8c 100644 --- a/test/src/lib/backoff.spec.ts +++ b/test/src/lib/backoff.spec.ts @@ -1,8 +1,8 @@ import { assert, expect } from 'chai'; import * as sinon from 'sinon'; -import { StatusError } from '../../../src/lib/errors'; -import { withBackoff, OnFailureInfo } from '../../../src/lib/backoff'; +import { StatusError } from '~/lib/errors'; +import { withBackoff, OnFailureInfo } from '~/lib/backoff'; const DEFAULT_OPTIONS = { maxRetries: 5, diff --git a/test/src/lib/fs-utils.spec.ts b/test/src/lib/fs-utils.spec.ts index 145c1b31..081de9e7 100644 --- a/test/src/lib/fs-utils.spec.ts +++ b/test/src/lib/fs-utils.spec.ts @@ -4,8 +4,8 @@ import { promises as fs } from 'fs'; import { spy, SinonSpy } from 'sinon'; import mock = require('mock-fs'); -import * as fsUtils from '../../../src/lib/fs-utils'; -import { rootMountPoint } from '../../../src/lib/constants'; +import * as fsUtils from '~/lib/fs-utils'; +import { rootMountPoint } from '~/lib/constants'; describe('lib/fs-utils', () => { const testFileName1 = 'file.1'; diff --git a/test/src/lib/json.spec.ts b/test/src/lib/json.spec.ts index 83792462..8c79f708 100644 --- a/test/src/lib/json.spec.ts +++ b/test/src/lib/json.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { equals, diff, prune, shallowDiff } from '../../../src/lib/json'; +import { equals, diff, prune, shallowDiff } from '~/lib/json'; describe('JSON utils', () => { describe('equals', () => { diff --git a/test/src/lib/legacy.spec.ts b/test/src/lib/legacy.spec.ts index 7b053bc8..7e5ecabc 100644 --- a/test/src/lib/legacy.spec.ts +++ b/test/src/lib/legacy.spec.ts @@ -3,10 +3,10 @@ import { isRight } from 'fp-ts/lib/Either'; import * as sinon from 'sinon'; import * as nock from 'nock'; -import { TargetState } from '../../../src/types'; -import * as config from '../../../src/config'; -import * as legacy from '../../../src/lib/legacy'; -import log from '../../../src/lib/supervisor-console'; +import { TargetState } from '~/src/types'; +import * as config from '~/src/config'; +import * as legacy from '~/lib/legacy'; +import log from '~/lib/supervisor-console'; describe('lib/legacy', () => { before(async () => { diff --git a/test/src/lib/lockfile.spec.ts b/test/src/lib/lockfile.spec.ts index 0efa55d9..e8311d87 100644 --- a/test/src/lib/lockfile.spec.ts +++ b/test/src/lib/lockfile.spec.ts @@ -4,9 +4,9 @@ import { stub, SinonStub } from 'sinon'; import { promises as fs } from 'fs'; import mock = require('mock-fs'); -import * as lockfile from '../../../src/lib/lockfile'; -import * as fsUtils from '../../../src/lib/fs-utils'; -import { BASE_LOCK_DIR, LOCKFILE_UID } from '../../../src/lib/update-lock'; +import * as lockfile from '~/lib/lockfile'; +import * as fsUtils from '~/lib/fs-utils'; +import { BASE_LOCK_DIR, LOCKFILE_UID } from '~/lib/update-lock'; describe('lib/lockfile', () => { const lockPath = `${BASE_LOCK_DIR}/1234567/one/updates.lock`; diff --git a/test/src/lib/system-info.spec.ts b/test/src/lib/system-info.spec.ts index 9a269775..ca0d89f0 100644 --- a/test/src/lib/system-info.spec.ts +++ b/test/src/lib/system-info.spec.ts @@ -3,8 +3,8 @@ import { SinonStub, stub } from 'sinon'; import { promises as fs } from 'fs'; import * as systeminformation from 'systeminformation'; -import * as fsUtils from '../../../src/lib/fs-utils'; -import * as sysInfo from '../../../src/lib/system-info'; +import * as fsUtils from '~/lib/fs-utils'; +import * as sysInfo from '~/lib/system-info'; describe('System information', () => { before(() => { diff --git a/test/src/lib/update-lock.spec.ts b/test/src/lib/update-lock.spec.ts index fca9d828..6a8af8ff 100644 --- a/test/src/lib/update-lock.spec.ts +++ b/test/src/lib/update-lock.spec.ts @@ -4,12 +4,12 @@ import * as path from 'path'; import { promises as fs } from 'fs'; import mockFs = require('mock-fs'); -import * as updateLock from '../../../src/lib/update-lock'; -import * as constants from '../../../src/lib/constants'; -import { UpdatesLockedError } from '../../../src/lib/errors'; -import * as config from '../../../src/config'; -import * as lockfile from '../../../src/lib/lockfile'; -import * as fsUtils from '../../../src/lib/fs-utils'; +import * as updateLock from '~/lib/update-lock'; +import * as constants from '~/lib/constants'; +import { UpdatesLockedError } from '~/lib/errors'; +import * as config from '~/src/config'; +import * as lockfile from '~/lib/lockfile'; +import * as fsUtils from '~/lib/fs-utils'; describe('lib/update-lock', () => { const appId = 1234567; From c9667f81f0a8ede6941b67ca0ba8e7f27c247425 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Mon, 22 Aug 2022 14:53:27 -0400 Subject: [PATCH 5/5] Update README --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5afc7ecb..1d8117a0 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ balena build -d raspberrypi4-64 -A aarch64 ## Testing -You can run some unit tests with: +You can run the supervisor test suite with: ``` npm test @@ -191,14 +191,14 @@ which ensures that the environment is exactly the same. #### Running specific tests quickly -You can run specific tests quickly with the `test:fast` script by matching with test suites (describe) or test cases (it) using a string or regexp: +You can run specific tests quickly with the `test:node` script by matching with test suites (describe) or test cases (it) using a string or regexp: ```sh -npm run test:fast -- -g spawnJournalctl +npm run test:node -- -g spawnJournalctl -npm run test:fast -- -g "detect a V2 delta" +npm run test:node -- -g "detect a V2 delta" -npm run test:fast -- -g (GET|POST|PUT|DELETE) +npm run test:node -- -g (GET|POST|PUT|DELETE) ``` The --grep option, when specified, will trigger mocha to only run tests matching the given pattern which is internally compiled to a RegExp.