8000 stabilize testcontainer test with success check · avdim/github-script@d967ecc · GitHub
[go: up one dir, main page]

Skip to content

Commit d967ecc

Browse files
committed
stabilize testcontainer test with success check
1 parent c46c703 commit d967ecc

File tree

6 files changed

+87
-42
lines changed

6 files changed

+87
-42
lines changed

__test__/invoke_sh.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// const exec = util.promisify(require('child_process').exec);
2+
// async function lsWithGrep() {
3+
// try {
4+
// const {stdout, stderr} = await exec('npm ci && npm publish', {
5+
// cwd: path.resolve(ROOT_PATH, "test-package-dir")
6+
// });
7+
// console.log('stdout:', stdout);
8+
// console.log('stderr:', stderr);
9+
// } catch (err) {
10+
// console.error("my catch, err:", err);
11+
// }
12+
// }
13+
// await lsWithGrep();

__test__/migrate.test.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,49 @@ const {GenericContainer} = require("testcontainers");
88
const util = require('util');
99

1010
const MODULE_NAME = 'test-package'
11-
const FROM = 'http://localhost:55551'
1211
const TO = 'http://localhost:55552'
1312
const ROOT_PATH = path.resolve(__dirname, "../");
13+
const DEFAULT_NPM_PORT = 4873
1414

1515
describe('migrate', () => {
1616
test('test1', async () => {
17-
jest.setTimeout(2 * 60_000);
18-
const environment = await new DockerComposeEnvironment(
19-
ROOT_PATH,
20-
"npm-registries.yml"
21-
).up();
22-
npmCliLogin("Username", "Password", "test@example.com", "http://localhost:55551")
23-
npmCliLogin("Username", "Password", "test@example.com", "http://localhost:55552")
24-
//sh: node_modules/.bin/npm-cli-login -u Username -p Password -e test@example.com -r http://localhost:55551
17+
jest.setTimeout(3 * 60_000);
18+
19+
const buildContext = path.resolve(ROOT_PATH, "test-package-dir");
20+
const container = await GenericContainer.fromDockerfile(buildContext).build();
21+
22+
const startedContainer = await container
23+
.withExposedPorts(DEFAULT_NPM_PORT)
24+
.start();
25+
//todo speedup to local test
26+
// const startedContainer = await new GenericContainer("temp/npm_test_package", "tag1")
27+
// .withExposedPorts(DEFAULT_NPM_PORT)
28+
// .start()
2529

26-
//todo publish test-package
27-
const exec = util.promisify(require('child_process').exec);
28-
async function lsWithGrep() {
29-
try {
30-
const {stdout, stderr} = await exec('npm ci && npm publish', {
31-
cwd: path.resolve(ROOT_PATH, "test-package-dir")
32-
});
33-
console.log('stdout:', stdout);
34-
console.log('stderr:', stderr);
35-
} catch (err) {
36-
console.error("my catch, err:", err);
37-
}
30+
let mappedFromPort: number = startedContainer.getMappedPort(DEFAULT_NPM_PORT);
31+
console.log("mappedPort: ", mappedFromPort)
32+
const FROM = `http://localhost:${mappedFromPort}`
33+
34+
function timeout(ms: number) {
35+
return new Promise(resolve => setTimeout(resolve, ms));
3836
}
39-
await lsWithGrep();
37+
console.log("before timeout", new Date().getSeconds())
38+
await timeout(5_000)
39+
console.log("after timeout", new Date().getSeconds())
40+
41+
// const environment = await new DockerComposeEnvironment(ROOT_PATH, "npm-registries.yml").up();
42+
npmCliLogin("Username", "Password", "test@example.com", FROM)
43+
// npmCliLogin("Username", "Password", "test@example.com", TO)
44+
//sh: node_modules/.bin/npm-cli-login -u Username -p Password -e test@example.com -r http://localhost:55551
4045

4146
try {
42-
console.log("migrate fun: ", migrate)
43-
await migrate(MODULE_NAME, FROM, TO, {debug: false})
47+
await migrate(MODULE_NAME, FROM, TO, {debug: true})
4448
.then((migrated: any) => console.log("migrated", migrated)) // list of migrated packages
4549
.catch((err: any) => console.error("my err", err))
4650
let resultVersions: Array<string> = await npmUtils.getVersionList(MODULE_NAME, TO);
47-
// expect(resultVersions.indexOf("1.0.1") >= 0).toEqual(true)//todo
51+
expect(resultVersions.indexOf("1.0.1") >= 0).toEqual(true)
4852
} finally {
49-
await environment.down()
53+
// await environment.down()
5054
}
5155

5256
})

integration_test.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ function clear {
1313

1414
clear
1515

16-
#docker-compose --file npm-registries.yml up -d
17-
#sleep 4
16+
docker-compose --file npm-registries.yml up -d
17+
sleep 2
1818
#echo "start"
1919

20-
#npm login --registry=http://localhost:55551 --scope=@tutu
2120
#node_modules/.bin/npm-cli-login -u Username -p Password -e test@example.com -r http://localhost:55551
22-
#node_modules/.bin/npm-cli-login -u Username -p Password -e test@example.com -r http://localhost:55552
21+
node_modules/.bin/npm-cli-login -u Username -p Password -e test@example.com -r http://localhost:55552
2322

2423
#cd test-package-dir
2524
#npm ci

npm-registries.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#docker-compose --file npm-registries.yml up
22
version: '2'
33
services:
4-
npm1:
5-
container_name: npm1
6-
image: "verdaccio/verdaccio:4.8.1"
7-
ports:
8-
- "55551:4873"
9-
volumes:
10-
- /var/run/docker.sock:/tmp/docker.sock:ro
4+
# npm1:
5+
# container_name: npm1
6+
# image: "verdaccio/verdaccio:4.8.1"
7+
# ports:
8+
# - "55551:4873"
9+
# volumes:
10+
# - /var/run/docker.sock:/tmp/docker.sock:ro
1111

1212
npm2:
1313
container_name: npm2
@@ -16,7 +16,7 @@ services:
1616
- "55552:4873"
1717
# expose:
1818
# - 8080
19-
environment:
20-
- VIRTUAL_HOST=localhost
21-
- VIRTUAL_PORT=8080
19+
# environment:
20+
# - VIRTUAL_HOST=localhost
21+
# - VIRTUAL_PORT=8080
2222

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"npm-cache-filename": "~1.0.2",
9494
"npm-install-checks": "~3.0.0",
9595
"npm-package-arg": "~4.2.1",
96-
"npm-registry-client": "~8.1.1",
96+
"npm-registry-client": "^8.1.1",
9797
"npm-user-validate": "~0.1.5",
9898
"npmlog": "~4.0.2",
9999
"once": "~1.4.0",

src/npm_utils.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,37 @@ const npm = require('./npm.js')
22
const mv = require('mv')
33
const curry = require('lodash.curry')
44
const async = require('async')
5+
const RegClient = require('npm-registry-client');
6+
const fs = require('fs')
57

68
const publishAsync = function (registry, path, callback) {
7-
9+
if (false) {//todo check true
10+
let regClient = new RegClient();
11+
let tgz = path + '.tgz'
12+
console.log("upload tgz: ", tgz)
13+
14+
regClient.publish(
15+
registry,
16+
{
17+
body: fs.createReadStream(tgz),
18+
metadata: {
19+
name: "test-package",//todo argument
20+
version: "1.0.1"
21+
},
22+
auth : {
23+
username: "Username",
24+
password: "Password",
25+
email: "test@example.com"
26+
}
27+
},
28+
(err, data) => {
29+
30+
if (err) return callback(err);
31+
32+
callback(null, path)
33+
}
34+
)
35+
} else {
836
npm.load({
937
registry: registry
1038
}, () => {
@@ -18,6 +46,7 @@ const publishAsync = function (registry, path, callback) {
1846
callback(null, path)
1947
})
2048
})
49+
}
2150
}
2251

2352
const getTarball = function (moduleName, registry, version, callback) {

0 commit comments

Comments
 (0)
0