From 1682d06e1d667c997be718746c48e1521ca4b44d Mon Sep 17 00:00:00 2001 From: Cristian Greco Date: Thu, 3 Aug 2023 18:52:48 +0100 Subject: [PATCH] Update guide and code for v10 of testcontainers-node (#2) --- .../index.adoc | 4 +- src/package-lock.json | 194 +++++++++++------- src/package.json | 4 +- src/src/customer-repository.test.js | 2 +- 4 files changed, 121 insertions(+), 83 deletions(-) diff --git a/guide/getting-started-with-testcontainers-for-nodejs/index.adoc b/guide/getting-started-with-testcontainers-for-nodejs/index.adoc index a996571..79cd5cb 100644 --- a/guide/getting-started-with-testcontainers-for-nodejs/index.adoc +++ b/guide/getting-started-with-testcontainers-for-nodejs/index.adoc @@ -36,12 +36,12 @@ Initialize a new Node.js project using the `npm init` command: npm init -y ---- -Add `pg`, `jest` and `testcontainers` as dependencies: +Add `pg`, `jest` and `@testcontainers/postgresql` as dependencies: [source,bash] ---- npm install pg --save -npm install jest testcontainers --save-dev +npm install jest @testcontainers/postgresql --save-dev ---- == Write the tests and solution diff --git a/src/package-lock.json b/src/package-lock.json index e907b3a..574065a 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -1,19 +1,19 @@ { - "name": "src", + "name": "tc-guide-getting-started-with-testcontainers-for-nodejs", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "src", + "name": "tc-guide-getting-started-with-testcontainers-for-nodejs", "version": "1.0.0", "license": "ISC", "dependencies": { "pg": "^8.11.0" }, "devDependencies": { - "jest": "^29.5.0", - "testcontainers": "^9.8.0" + "@testcontainers/postgresql": "^10.0.1", + "jest": "^29.5.0" } }, "node_modules/@ampproject/remapping": { @@ -975,13 +975,13 @@ "@sinonjs/commons": "^3.0.0" } }, - "node_modules/@types/archiver": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/@types/archiver/-/archiver-5.3.2.tgz", - "integrity": "sha512-IctHreBuWE5dvBDz/0WeKtyVKVRs4h75IblxOACL92wU66v+HGAfEYAOyXkOFphvRJMhuXdI9huDXpX0FC6lCw==", + "node_modules/@testcontainers/postgresql": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/@testcontainers/postgresql/-/postgresql-10.0.1.tgz", + "integrity": "sha512-nHJBJI2N3NOMQH5kY3r8i5qX6Ta4/fu+oUEIp3QssFTNh/5K25DJrAGiAKDHRHz4ffwlFK82P7dlIBiqNWlskw==", "dev": true, "dependencies": { - "@types/readdir-glob": "*" + "testcontainers": "^10.0.1" } }, "node_modules/@types/babel__core": { @@ -1025,26 +1025,6 @@ "@babel/types": "^7.20.7" } }, - "node_modules/@types/docker-modem": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/docker-modem/-/docker-modem-3.0.2.tgz", - "integrity": "sha512-qC7prjoEYR2QEe6SmCVfB1x3rfcQtUr1n4x89+3e0wSTMQ/KYCyf+/RAA9n2tllkkNc6//JMUZePdFRiGIWfaQ==", - "dev": true, - "dependencies": { - "@types/node": "*", - "@types/ssh2": "*" - } - }, - "node_modules/@types/dockerode": { - "version": "3.3.18", - "resolved": "https://registry.npmjs.org/@types/dockerode/-/dockerode-3.3.18.tgz", - "integrity": "sha512-4EcP136jNMBZQ4zTHlI1VP2RpIQ2uJvRpjta3W2Cc7Ti7rk2r3TgVKjxR0Tb3NrT9ObXvl7Tv5nxra6BHEpkWg==", - "dev": true, - "dependencies": { - "@types/docker-modem": "*", - "@types/node": "*" - } - }, "node_modules/@types/graceful-fs": { "version": "4.1.6", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.6.tgz", @@ -1090,24 +1070,6 @@ "integrity": "sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA==", "dev": true }, - "node_modules/@types/readdir-glob": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@types/readdir-glob/-/readdir-glob-1.1.1.tgz", - "integrity": "sha512-ImM6TmoF8bgOwvehGviEj3tRdRBbQujr1N+0ypaln/GWjaerOB26jb93vsRHmdMtvVQZQebOlqt2HROark87mQ==", - "dev": true, - "dependencies": { - "@types/node": "*" - } - }, - "node_modules/@types/ssh2": { - "version": "1.11.11", - "resolved": "https://registry.npmjs.org/@types/ssh2/-/ssh2-1.11.11.tgz", - "integrity": "sha512-LdnE7UBpvHCgUznvn2fwLt2hkaENcKPFqOyXGkvyTLfxCXBN6roc1RmECNYuzzbHePzD3PaAov5rri9hehzx9Q==", - "dev": true, - "dependencies": { - "@types/node": "^18.11.18" - } - }, "node_modules/@types/ssh2-streams": { "version": "0.1.9", "resolved": "https://registry.npmjs.org/@types/ssh2-streams/-/ssh2-streams-0.1.9.tgz", @@ -1117,12 +1079,6 @@ "@types/node": "*" } }, - "node_modules/@types/ssh2/node_modules/@types/node": { - "version": "18.16.16", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.16.tgz", - "integrity": "sha512-NpaM49IGQQAUlBhHMF82QH80J08os4ZmyF9MkpCzWAGuOHqE4gTEbhzd7L3l5LmWuZ6E0OiC1FweQ4tsiW35+g==", - "dev": true - }, "node_modules/@types/stack-utils": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", @@ -1295,6 +1251,12 @@ "integrity": "sha512-coglx5yIWuetakm3/1dsX9hxCNox22h7+V80RQOu2XUUMidtArxKoZoOtHUPuR84SycKTXzgGzAUR5hJxujyJQ==", "dev": true }, + "node_modules/b4a": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz", + "integrity": "sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw==", + "dev": true + }, "node_modules/babel-jest": { "version": "29.5.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.5.0.tgz", @@ -1837,12 +1799,12 @@ } }, "node_modules/docker-compose": { - "version": "0.23.19", - "resolved": "https://registry.npmjs.org/docker-compose/-/docker-compose-0.23.19.tgz", - "integrity": "sha512-v5vNLIdUqwj4my80wxFDkNH+4S85zsRuH29SO7dCWVWPCMt/ohZBsGN6g6KXWifT0pzQ7uOxqEKCYCDPJ8Vz4g==", + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/docker-compose/-/docker-compose-0.24.2.tgz", + "integrity": "sha512-2/WLvA7UZ6A2LDLQrYW0idKipmNBWhtfvrn2yzjC5PnHDzuFVj1zAZN6MJxVMKP0zZH8uzAK6OwVZYHGuyCmTw==", "dev": true, "dependencies": { - "yaml": "^1.10.2" + "yaml": "^2.2.2" }, "engines": { "node": ">= 6.0.0" @@ -2010,6 +1972,12 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/fast-fifo": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.0.tgz", + "integrity": "sha512-IgfweLvEpwyA4WgiQe9Nx6VV2QkML2NkvZnk1oKnIzXgXdWxuhF7zw4DvLTPZJn6PIUneiAXPF24QmoEqHTjyw==", + "dev": true + }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -3262,9 +3230,9 @@ "dev": true }, "node_modules/node-fetch": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", - "integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==", + "version": "2.6.12", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz", + "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==", "dev": true, "dependencies": { "whatwg-url": "^5.0.0" @@ -3647,6 +3615,17 @@ "node": ">= 6" } }, + "node_modules/proper-lockfile": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/proper-lockfile/-/proper-lockfile-4.1.2.tgz", + "integrity": "sha512-TjNPblN4BwAWMXU8s9AEz4JmQxnD1NNL7bNOY/AKUzyamc379FWASUhc/K1pL2noVb+XmZKLL68cjzLsiOAMaA==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.4", + "retry": "^0.12.0", + "signal-exit": "^3.0.2" + } + }, "node_modules/properties-reader": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/properties-reader/-/properties-reader-2.2.0.tgz", @@ -3685,6 +3664,12 @@ } ] }, + "node_modules/queue-tick": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/queue-tick/-/queue-tick-1.0.1.tgz", + "integrity": "sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag==", + "dev": true + }, "node_modules/react-is": { "version": "18.2.0", "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", @@ -3791,6 +3776,30 @@ "node": ">=10" } }, + "node_modules/retry": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", + "integrity": "sha512-9LkiTwjUh6rT555DtE9rTX+BKByPfrMzEAtnlEtdEwr3Nkffwiihqe2bWADg+OQRjt9gl6ICdmB/ZFDCGAtSow==", + "dev": true, + "engines": { + "node": ">= 4" + } + }, + "node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -3957,6 +3966,16 @@ "node": ">=10" } }, + "node_modules/streamx": { + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.15.0.tgz", + "integrity": "sha512-HcxY6ncGjjklGs1xsP1aR71INYcsXFJet5CU1CHqihQ2J5nOsbd4OjgjHO42w/4QNv9gZb3BueV+Vxok5pLEXg==", + "dev": true, + "dependencies": { + "fast-fifo": "^1.1.0", + "queue-tick": "^1.0.1" + } + }, "node_modules/string_decoder": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", @@ -4060,15 +4079,25 @@ } }, "node_modules/tar-fs": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", - "integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.4.tgz", + "integrity": "sha512-5AFQU8b9qLfZCX9zp2duONhPmZv0hGYiBPJsyUdqMjzq/mqVpy/rEUSeHk1+YitmxugaptgBh5oDGU3VsAJq4w==", "dev": true, "dependencies": { - "chownr": "^1.1.1", "mkdirp-classic": "^0.5.2", "pump": "^3.0.0", - "tar-stream": "^2.1.4" + "tar-stream": "^3.1.5" + } + }, + "node_modules/tar-fs/node_modules/tar-stream": { + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.1.6.tgz", + "integrity": "sha512-B/UyjYwPpMBv+PaFSWAmtYjwdrlEaZQEhMIBFNC5oEG8lpiW8XjcSdmEaClj28ArfKScKHs2nshz3k2le6crsg==", + "dev": true, + "dependencies": { + "b4a": "^1.6.4", + "fast-fifo": "^1.2.0", + "streamx": "^2.15.0" } }, "node_modules/tar-stream": { @@ -4102,28 +4131,37 @@ } }, "node_modules/testcontainers": { - "version": "9.8.0", - "resolved": "https://registry.npmjs.org/testcontainers/-/testcontainers-9.8.0.tgz", - "integrity": "sha512-61IlJeVrUbS5JlAgM/N0koFnRxsID+vDap7CUmgaHXSGxmFofCiokB7kD96c1BtDWGOznrd7lTAPGSkd3RVkPA==", + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/testcontainers/-/testcontainers-10.0.1.tgz", + "integrity": "sha512-eS76/xz0mOYL9Go0i8RKJh8CSi0xcFGzS2AS5ieNV9TRsHLKkB+2/isWk8iCy0C17YA17Cd3EHSRYCge/7REhQ==", "dev": true, "dependencies": { "@balena/dockerignore": "^1.0.2", - "@types/archiver": "^5.3.2", - "@types/dockerode": "^3.3.16", "archiver": "^5.3.1", "async-lock": "^1.4.0", "byline": "^5.0.0", "debug": "^4.3.4", - "docker-compose": "^0.23.19", + "docker-compose": "^0.24.2", "dockerode": "^3.3.5", "get-port": "^5.1.1", - "node-fetch": "^2.6.9", + "node-fetch": "^2.6.12", + "proper-lockfile": "^4.1.2", "properties-reader": "^2.2.0", "ssh-remote-port-forward": "^1.0.4", - "tar-fs": "^2.1.1" + "tar-fs": "^3.0.4", + "tmp": "^0.2.1" + } + }, + "node_modules/tmp": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", + "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", + "dev": true, + "dependencies": { + "rimraf": "^3.0.0" }, "engines": { - "node": ">= 10.16" + "node": ">=8.17.0" } }, "node_modules/tmpl": { @@ -4342,12 +4380,12 @@ "dev": true }, "node_modules/yaml": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", - "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz", + "integrity": "sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==", "dev": true, "engines": { - "node": ">= 6" + "node": ">= 14" } }, "node_modules/yargs": { diff --git a/src/package.json b/src/package.json index 5432f92..3aaf4b7 100644 --- a/src/package.json +++ b/src/package.json @@ -13,7 +13,7 @@ "pg": "^8.11.0" }, "devDependencies": { - "jest": "^29.5.0", - "testcontainers": "^9.8.0" + "@testcontainers/postgresql": "^10.0.1", + "jest": "^29.5.0" } } diff --git a/src/src/customer-repository.test.js b/src/src/customer-repository.test.js index ef54c82..ee6c2c0 100644 --- a/src/src/customer-repository.test.js +++ b/src/src/customer-repository.test.js @@ -1,5 +1,5 @@ const { Client } = require("pg"); -const { PostgreSqlContainer } = require("testcontainers"); +const { PostgreSqlContainer } = require("@testcontainers/postgresql"); const { createCustomerTable, createCustomer, getCustomers } = require("./customer-repository"); describe("Customer Repository", () => {