Skip to content

Commit 642cdfe

Browse files
committed
test(filesystem): fix tests for windows
1 parent d696e87 commit 642cdfe

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

__tests__/templating/filesystem.test.ts

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ jest.mock('pkg-install');
55
jest.mock('../../src/utils/fs');
66
jest.mock('../../src/utils/logger');
77

8-
import path from 'path';
9-
import { install } from 'pkg-install';
108
import { fsHelpers } from '@twilio-labs/serverless-api';
119
import got from 'got';
10+
import path, { join } from 'path';
11+
import { install } from 'pkg-install';
1212
import { mocked } from 'ts-jest/utils';
1313
import { writeFiles } from '../../src/templating/filesystem';
1414
import {
1515
downloadFile,
1616
fileExists,
17+
mkdir,
1718
readFile,
1819
writeFile,
19-
mkdir,
2020
} from '../../src/utils/fs';
2121

2222
beforeEach(() => {
@@ -108,22 +108,22 @@ test('installation with basic functions', async () => {
108108
expect(downloadFile).toHaveBeenCalledTimes(3);
109109
expect(downloadFile).toHaveBeenCalledWith(
110110
'https://example.com/.env',
111-
'testing/.env'
111+
join('testing', '.env')
112112
);
113113
expect(downloadFile).toHaveBeenCalledWith(
114114
'https://example.com/hello.js',
115-
'testing/functions/example/hello.js'
115+
join('testing', 'functions', 'example', 'hello.js')
116116
);
117117
expect(downloadFile).toHaveBeenCalledWith(
118118
'https://example.com/README.md',
119-
'testing/readmes/example/hello.md'
119+
join('testing', 'readmes', 'example', 'hello.md')
120120
);
121121

122122
expect(mkdir).toHaveBeenCalledTimes(2);
123-
expect(mkdir).toHaveBeenCalledWith('testing/functions/example', {
123+
expect(mkdir).toHaveBeenCalledWith(join('testing', 'functions', 'example'), {
124124
recursive: true,
125125
});
126-
expect(mkdir).toHaveBeenCalledWith('testing/readmes/example', {
126+
expect(mkdir).toHaveBeenCalledWith(join('testing', 'readmes', 'example'), {
127127
recursive: true,
128128
});
129129
});
@@ -165,22 +165,22 @@ test('installation with functions and assets', async () => {
165165
expect(downloadFile).toHaveBeenCalledTimes(3);
166166
expect(downloadFile).toHaveBeenCalledWith(
167167
'https://example.com/.env',
168-
'testing/.env'
168+
join('testing', '.env')
169169
);
170170
expect(downloadFile).toHaveBeenCalledWith(
171171
'https://example.com/hello.js',
172-
'testing/functions/example/hello.js'
172+
join('testing', 'functions', 'example', 'hello.js')
173173
);
174174
expect(downloadFile).toHaveBeenCalledWith(
175175
'https://example.com/hello.wav',
176-
'testing/assets/example/hello.wav'
176+
join('testing', 'assets', 'example', 'hello.wav')
177177
);
178178

179179
expect(mkdir).toHaveBeenCalledTimes(2);
180-
expect(mkdir).toHaveBeenCalledWith('testing/functions/example', {
180+
expect(mkdir).toHaveBeenCalledWith(join('testing', 'functions', 'example'), {
181181
recursive: true,
182182
});
183-
expect(mkdir).toHaveBeenCalledWith('testing/assets/example', {
183+
expect(mkdir).toHaveBeenCalledWith(join('testing', 'assets', 'example'), {
184184
recursive: true,
185185
});
186186
});
@@ -228,23 +228,23 @@ test('installation with functions and assets and blank namespace', async () => {
228228
expect(downloadFile).toHaveBeenCalledTimes(4);
229229
expect(downloadFile).toHaveBeenCalledWith(
230230
'https://example.com/.env',
231-
'testing/.env'
231+
join('testing', '.env')
232232
);
233233
expect(downloadFile).toHaveBeenCalledWith(
234234
'https://example.com/hello.js',
235-
'testing/functions/hello.js'
235+
join('testing', 'functions', 'hello.js')
236236
);
237237
expect(downloadFile).toHaveBeenCalledWith(
238238
'https://example.com/hello.wav',
239-
'testing/assets/hello.wav'
239+
join('testing', 'assets', 'hello.wav')
240240
);
241241
expect(downloadFile).toHaveBeenCalledWith(
242242
'https://example.com/README.md',
243-
'testing/readmes/hello.md'
243+
join('testing', 'readmes', 'hello.md')
244244
);
245245

246246
expect(mkdir).toHaveBeenCalledTimes(1);
247-
expect(mkdir).toHaveBeenCalledWith('testing/readmes', {
247+
expect(mkdir).toHaveBeenCalledWith(join('testing', 'readmes'), {
248248
recursive: true,
249249
});
250250
});
@@ -275,6 +275,7 @@ test('installation with an empty dependency file', async () => {
275275
// buffer but depending on inputs `got` can actually return an object.
276276
// @ts-ignore
277277
mocked(got).mockImplementation(() =>
278+
//@ts-ignore
278279
Promise.resolve({ body: { dependencies: {} } })
279280
);
280281

@@ -308,7 +309,7 @@ test('installation with an empty dependency file', async () => {
308309
expect(downloadFile).toHaveBeenCalledTimes(1);
309310
expect(downloadFile).toHaveBeenCalledWith(
310311
'https://example.com/.env',
311-
'testing/.env'
312+
join('testing', '.env')
312313
);
313314

314315
expect(got).toHaveBeenCalledTimes(1);
@@ -324,6 +325,7 @@ test('installation with a dependency file', async () => {
324325
// buffer but depending on inputs `got` can actually return an object.
325326
// @ts-ignore
326327
mocked(got).mockImplementation(() =>
328+
// @ts-ignore
327329
Promise.resolve({
328330
body: { dependencies: { foo: '^1.0.0', got: '^6.9.0' } },
329331
})
@@ -359,7 +361,7 @@ test('installation with a dependency file', async () => {
359361
expect(downloadFile).toHaveBeenCalledTimes(1);
360362
expect(downloadFile).toHaveBeenCalledWith(
361363
'https://example.com/.env',
362-
'testing/.env'
364+
join('testing', '.env')
363365
);
364366

365367
expect(got).toHaveBeenCalledTimes(1);
@@ -382,6 +384,7 @@ test('installation with an existing dot-env file', async () => {
382384
// buffer but depending on inputs `got` can actually return an object.
383385
// @ts-ignore
384386
mocked(got).mockImplementation(() =>
387+
// @ts-ignore
385388
Promise.resolve({ body: 'HELLO=WORLD\n' })
386389
);
387390

@@ -410,7 +413,7 @@ test('installation with an existing dot-env file', async () => {
410413

411414
expect(writeFile).toHaveBeenCalledTimes(1);
412415
expect(writeFile).toHaveBeenCalledWith(
413-
'testing/.env',
416+
join('testing', '.env'),
414417
'# Comment\n' +
415418
'FOO=BAR\n' +
416419
'\n\n' +
@@ -429,7 +432,7 @@ test('installation with overlapping function files throws errors before writing'
429432
);
430433

431434
mocked(fileExists).mockImplementation(p =>
432-
Promise.resolve(p == 'functions/example/hello.js')
435+
Promise.resolve(p == join('functions', 'example', 'hello.js'))
433436
);
434437

435438
await expect(
@@ -468,7 +471,7 @@ test('installation with overlapping asset files throws errors before writing', a
468471
);
469472

470473
mocked(fileExists).mockImplementation(p =>
471-
Promise.resolve(p == 'assets/example/hello.wav')
474+
Promise.resolve(p == join('assets', 'example', 'hello.wav'))
472475
);
473476

474477
await expect(
@@ -493,7 +496,7 @@ test('installation with overlapping asset files throws errors before writing', a
493496
directory: '',
494497
},
495498
],
496-
'./',
499+
join('.', path.sep),
497500
'example',
498501
'hello'
499502
)
@@ -540,37 +543,37 @@ test('installation with functions and assets in nested directories', async () =>
540543
directory: '',
541544
},
542545
],
543-
'./testing/',
546+
join('.', 'testing'),
544547
'example',
545548
'hello'
546549
);
547550

548551
expect(downloadFile).toHaveBeenCalledTimes(4);
549552
expect(downloadFile).toHaveBeenCalledWith(
550553
'https://example.com/.env',
551-
'testing/.env'
554+
join('testing', '.env')
552555
);
553556
expect(downloadFile).toHaveBeenCalledWith(
554557
'https://example.com/hello.js',
555-
'testing/functions/example/admin/hello.js'
558+
join('testing', 'functions', 'example', 'admin', 'hello.js')
556559
);
557560
expect(downloadFile).toHaveBeenCalledWith(
558561
'https://example.com/README.md',
559-
'testing/readmes/example/hello.md'
562+
join('testing', 'readmes', 'example', 'hello.md')
560563
);
561564
expect(downloadFile).toHaveBeenCalledWith(
562565
'https://example.com/woohoo.jpg',
563-
'testing/assets/example/success/woohoo.jpg'
566+
join('testing', 'assets', 'example', 'success', 'woohoo.jpg')
564567
);
565568

566569
expect(mkdir).toHaveBeenCalledTimes(3);
567-
expect(mkdir).toHaveBeenCalledWith('testing/functions/example', {
570+
expect(mkdir).toHaveBeenCalledWith(join('testing', 'functions', 'example'), {
568571
recursive: true,
569572
});
570-
expect(mkdir).toHaveBeenCalledWith('testing/readmes/example', {
573+
expect(mkdir).toHaveBeenCalledWith(join('testing', 'readmes', 'example'), {
571574
recursive: true,
572575
});
573-
expect(mkdir).toHaveBeenCalledWith('testing/assets/example', {
576+
expect(mkdir).toHaveBeenCalledWith(join('testing', 'assets', 'example'), {
574577
recursive: true,
575578
});
576579
});

0 commit comments

Comments
 (0)