Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit 3cf7454

Browse files
committed
removing --strip-components because it's "removing one level", updated "should log output" because of deprecations, updated "should copy to remote" to make sure it does not conflict with other builds, added force_color=0 to ensure that "color" is not appended, fixing babelNode resolve
1 parent e88c3b0 commit 3cf7454

File tree

7 files changed

+39
-25
lines changed

7 files changed

+39
-25
lines changed

jest.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
process.env.FORCE_COLOR=0;
2+
13
module.exports = {
24
testEnvironment: 'node',
35
roots: ['packages'],

packages/shipit-cli/tests/integration.test.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ import { exec } from 'ssh-pool'
33

44
const shipitCli = path.resolve(__dirname, '../src/cli.js')
55
const shipitFile = path.resolve(__dirname, './sandbox/shipitfile.babel.js')
6+
const babelNode = require.resolve('@babel/node/bin/babel-node');
67

78
describe('shipit-cli', () => {
89
it('should run a local task', async () => {
9-
const { stdout } = await exec(
10-
`babel-node ${shipitCli} --shipitfile ${shipitFile} test localHello`,
11-
)
10+
let { stdout } = await exec(`FORCE_COLOR=0 ${babelNode} ${shipitCli} --shipitfile ${shipitFile} test localHello`)
11+
stdout = stdout.trim();
12+
1213
expect(stdout).toMatch(/Running 'localHello' task.../)
1314
expect(stdout).toMatch(/Running "echo "hello"" on local./)
1415
expect(stdout).toMatch(/@ hello/)
1516
expect(stdout).toMatch(/Finished 'localHello' after/)
1617
}, 10000)
1718

1819
it('should run a remote task', async () => {
19-
const { stdout } = await exec(
20-
`babel-node ${shipitCli} --shipitfile ${shipitFile} test remoteUser`,
21-
)
20+
let { stdout } = await exec(`FORCE_COLOR=0 ${babelNode} ${shipitCli} --shipitfile ${shipitFile} test remoteUser`)
21+
stdout = stdout.trim();
22+
2223
expect(stdout).toMatch(/Running 'remoteUser' task.../)
2324
expect(stdout).toMatch(/Running "echo \$USER" on host "test.shipitjs.com"./)
2425
expect(stdout).toMatch(/@test.shipitjs.com deploy/)
@@ -27,7 +28,7 @@ describe('shipit-cli', () => {
2728

2829
it('should work with "~"', async () => {
2930
const { stdout } = await exec(
30-
`babel-node ${shipitCli} --shipitfile ${shipitFile} test cwdSsh`,
31+
`${babelNode} ${shipitCli} --shipitfile ${shipitFile} test cwdSsh`,
3132
)
3233
expect(stdout).toMatch(/@test.shipitjs.com \/home\/deploy\/\.ssh/)
3334
}, 10000)

packages/shipit-deploy/tests/integration.test.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import { exec } from 'ssh-pool'
44

55
const shipitCli = path.resolve(__dirname, '../../shipit-cli/src/cli.js')
66
const shipitFile = path.resolve(__dirname, './sandbox/shipitfile.babel.js')
7+
const babelNode = require.resolve('@babel/node/bin/babel-node');
78

89
describe('shipit-cli', () => {
910
it('should run a local task', async () => {
1011
try {
1112
await exec(
12-
`babel-node ${shipitCli} --shipitfile ${shipitFile} test deploy`,
13+
`${babelNode} ${shipitCli} --shipitfile ${shipitFile} test deploy`,
1314
)
1415
} catch (error) {
1516
// eslint-disable-next-line no-console
@@ -19,7 +20,7 @@ describe('shipit-cli', () => {
1920
}
2021

2122
const { stdout: lsReleases } = await exec(
22-
`babel-node ${shipitCli} --shipitfile ${shipitFile} test ls-releases`,
23+
`${babelNode} ${shipitCli} --shipitfile ${shipitFile} test ls-releases`,
2324
)
2425

2526
const latestRelease = lsReleases
@@ -28,13 +29,13 @@ describe('shipit-cli', () => {
2829
.match(/\d{14}/)[0]
2930

3031
const { stdout: lsCurrent } = await exec(
31-
`babel-node ${shipitCli} --shipitfile ${shipitFile} test ls-current`,
32+
`${babelNode} ${shipitCli} --shipitfile ${shipitFile} test ls-current`,
3233
)
3334

3435
const currentRelease = lsCurrent
3536
.split('\n')[3]
3637
.match(/releases\/(\d{14})/)[1]
3738

3839
expect(latestRelease).toBe(currentRelease)
39-
}, 25000)
40+
}, 30000)
4041
})

packages/ssh-pool/src/Connection.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ describe('Connection', () => {
312312
expect.any(Function),
313313
])
314314
expect(exec.mock.calls[4]).toEqual([
315-
'ssh user@host "cd /x/y/z && tar --strip-components=1 -xzf foo.tar.gz"',
315+
'ssh user@host "cd /x/y/z && tar -xzf foo.tar.gz"',
316316
{ maxBuffer: 1024000 },
317317
expect.any(Function),
318318
])
@@ -351,7 +351,7 @@ describe('Connection', () => {
351351
expect.any(Function),
352352
])
353353
expect(exec.mock.calls[4]).toEqual([
354-
'cd /x/y/z && tar --strip-components=1 -xzf foo.tar.gz',
354+
'cd /x/y/z && tar -xzf foo.tar.gz',
355355
{ maxBuffer: 1024000 },
356356
expect.any(Function),
357357
])
@@ -392,7 +392,7 @@ describe('Connection', () => {
392392
expect.any(Function),
393393
])
394394
expect(exec.mock.calls[4]).toEqual([
395-
'ssh -p 12345 -i /path/to/key user@host "cd /x/y/z && tar --strip-components=1 -xzf foo.tar.gz"',
395+
'ssh -p 12345 -i /path/to/key user@host "cd /x/y/z && tar -xzf foo.tar.gz"',
396396
{ maxBuffer: 1024000 },
397397
expect.any(Function),
398398
])
@@ -481,8 +481,8 @@ describe('Connection', () => {
481481
'/src/dir',
482482
'user@host:/dest/dir',
483483
)
484-
expect(output.stdout[0].toString()).toBe('@host first line\n')
485-
expect(output.stderr[0].toString()).toBe('@host-err an error\n')
484+
expect(output.stdout.toString()).toContain('@host first line\n')
485+
expect(output.stderr.toString()).toContain('@host-err an error\n')
486486
})
487487
})
488488
})

packages/ssh-pool/src/commands/tar.js

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export function formatTarCommand({ file, archive, excludes, mode }) {
1818
}
1919
case 'extract': {
2020
requireArgs(['archive'], { file, archive }, 'tar')
21-
args = [...args, '--strip-components=1']
2221
args = [...args, '-xzf', archive]
2322
return joinCommandArgs(args)
2423
}

packages/ssh-pool/src/commands/tar.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('tar', () => {
5454
archive: 'file.tar.gz',
5555
mode: 'extract',
5656
}),
57-
).toBe('tar --strip-components=1 -xzf file.tar.gz')
57+
).toBe('tar -xzf file.tar.gz')
5858
})
5959

6060
it('should support "excludes"', () => {

packages/ssh-pool/tests/integration.test.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import path from 'path'
1+
import {resolve, basename} from 'path'
2+
import {copyFileSync, unlinkSync} from 'fs';
23

34
const sshPool = require('../src')
45

@@ -7,7 +8,7 @@ describe('ssh-pool', () => {
78

89
beforeEach(() => {
910
pool = new sshPool.ConnectionPool(['[email protected]'], {
10-
key: path.resolve(__dirname, '../../../ssh/id_rsa'),
11+
key: resolve(__dirname, '../../../ssh/id_rsa'),
1112
})
1213
})
1314

@@ -25,9 +26,19 @@ describe('ssh-pool', () => {
2526
}, 10000)
2627

2728
it('should copy to remote', async () => {
28-
await pool.scpCopyToRemote(
29-
path.resolve(__dirname, '__fixtures__/test.txt'),
30-
'./',
31-
)
32-
}, 20000)
29+
const time = (+new Date);
30+
const sourceFile = resolve(__dirname, '__fixtures__/test.txt')
31+
const targetFile = `${__dirname}/__fixtures__/test.${time}.txt`;
32+
33+
copyFileSync(sourceFile, targetFile);
34+
35+
try {
36+
await pool.scpCopyToRemote(targetFile, './',);
37+
const [{ stdout: first }] = await pool.run(`cd ./ && cat ${basename(targetFile)}`);
38+
expect(first).toBe('Hello\n')
39+
} finally {
40+
unlinkSync(targetFile);
41+
}
42+
43+
}, 1e6)
3344
})

0 commit comments

Comments
 (0)