Skip to content

Commit 3be46b1

Browse files
author
bweigel
committed
fix tests with other includes
1 parent 7c6b3aa commit 3be46b1

File tree

1 file changed

+107
-55
lines changed

1 file changed

+107
-55
lines changed

test.js

Lines changed: 107 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ test('py3.6 can package flask with hashes', t => {
135135
process.chdir('tests/base');
136136
const path = npm(['pack', '../..']);
137137
npm(['i', path]);
138-
sls([`--pythonBin=${getPythonBin(3)}`, '--fileName=requirements-w-hashes.txt', 'package']);
138+
sls([
139+
`--pythonBin=${getPythonBin(3)}`,
140+
'--fileName=requirements-w-hashes.txt',
141+
'package'
142+
]);
139143
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
140144
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
141145
t.end();
@@ -200,7 +204,7 @@ test('py3.6 can package flask with slim & slimPatterns options', t => {
200204
t.end();
201205
});
202206

203-
test('py3.6 doesn\'t package bottle with noDeploy option', t => {
207+
test("py3.6 doesn't package bottle with noDeploy option", t => {
204208
process.chdir('tests/base');
205209
const path = npm(['pack', '../..']);
206210
npm(['i', path]);
@@ -224,14 +228,14 @@ test(
224228
process.chdir('tests/base');
225229
const path = npm(['pack', '../..']);
226230
npm(['i', path]);
227-
sls([
228-
'--dockerizePip=true',
229-
'package'
230-
]);
231+
sls(['--dockerizePip=true', 'package']);
231232

232233
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
233234
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
234-
t.false(zipfiles.includes(`boto3${sep}__init__.py`), 'boto3 is NOT packaged');
235+
t.false(
236+
zipfiles.includes(`boto3${sep}__init__.py`),
237+
'boto3 is NOT packaged'
238+
);
235239
t.end();
236240
},
237241
{ skip: !canUseDocker() }
@@ -292,11 +296,7 @@ test(
292296
process.chdir('tests/base');
293297
const path = npm(['pack', '../..']);
294298
npm(['i', path]);
295-
sls([
296-
'--dockerizePip=true',
297-
'--zip=true',
298-
'package'
299-
]);
299+
sls(['--dockerizePip=true', '--zip=true', 'package']);
300300

301301
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
302302
const zippedReqs = listRequirementsZipFiles(
@@ -306,7 +306,10 @@ test(
306306
zipfiles.includes('.requirements.zip'),
307307
'zipped requirements are packaged'
308308
);
309-
t.true(zipfiles.includes(`unzip_requirements.py`), 'unzip util is packaged');
309+
t.true(
310+
zipfiles.includes(`unzip_requirements.py`),
311+
'unzip util is packaged'
312+
);
310313
t.false(
311314
zipfiles.includes(`flask${sep}__init__.py`),
312315
"flask isn't packaged on its own"
@@ -326,12 +329,7 @@ test(
326329
process.chdir('tests/base');
327330
const path = npm(['pack', '../..']);
328331
npm(['i', path]);
329-
sls([
330-
'--dockerizePip=true',
331-
'--zip=true',
332-
'--slim=true',
333-
'package'
334-
]);
332+
sls(['--dockerizePip=true', '--zip=true', '--slim=true', 'package']);
335333

336334
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
337335
const zippedReqs = listRequirementsZipFiles(
@@ -341,7 +339,10 @@ test(
341339
zipfiles.includes('.requirements.zip'),
342340
'zipped requirements are packaged'
343341
);
344-
t.true(zipfiles.includes(`unzip_requirements.py`), 'unzip util is packaged');
342+
t.true(
343+
zipfiles.includes(`unzip_requirements.py`),
344+
'unzip util is packaged'
345+
);
345346
t.false(
346347
zipfiles.includes(`flask${sep}__init__.py`),
347348
"flask isn't packaged on its own"
@@ -407,7 +408,12 @@ test(
407408
copySync('_slimPatterns.yml', 'slimPatterns.yml');
408409
const path = npm(['pack', '../..']);
409410
npm(['i', path]);
410-
sls([`--pythonBin=${getPythonBin(2)}`, '--dockerizePip=true', '--slim=true', 'package']);
411+
sls([
412+
`--pythonBin=${getPythonBin(2)}`,
413+
'--dockerizePip=true',
414+
'--slim=true',
415+
'package'
416+
]);
411417
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
412418
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
413419
t.deepEqual(
@@ -425,7 +431,7 @@ test(
425431
{ skip: !canUseDocker() }
426432
);
427433

428-
test('py2.7 doesn\'t package bottle with noDeploy option', t => {
434+
test("py2.7 doesn't package bottle with noDeploy option", t => {
429435
process.chdir('tests/base');
430436
const path = npm(['pack', '../..']);
431437
npm(['i', path]);
@@ -464,7 +470,10 @@ test(
464470
zipfiles.includes('.requirements.zip'),
465471
'zipped requirements are packaged'
466472
);
467-
t.true(zipfiles.includes(`unzip_requirements.py`), 'unzip util is packaged');
473+
t.true(
474+
zipfiles.includes(`unzip_requirements.py`),
475+
'unzip util is packaged'
476+
);
468477
t.false(
469478
zipfiles.includes(`flask${sep}__init__.py`),
470479
"flask isn't packaged on its own"
@@ -500,7 +509,10 @@ test(
500509
zipfiles.includes('.requirements.zip'),
501510
'zipped requirements are packaged'
502511
);
503-
t.true(zipfiles.includes(`unzip_requirements.py`), 'unzip util is packaged');
512+
t.true(
513+
zipfiles.includes(`unzip_requirements.py`),
514+
'unzip util is packaged'
515+
);
504516
t.false(
505517
zipfiles.includes(`flask${sep}__init__.py`),
506518
"flask isn't packaged on its own"
@@ -520,15 +532,14 @@ test(
520532
process.chdir('tests/base');
521533
const path = npm(['pack', '../..']);
522534
npm(['i', path]);
523-
sls([
524-
`--pythonBin=${getPythonBin(2)}`,
525-
'--dockerizePip=true',
526-
'package'
527-
]);
535+
sls([`--pythonBin=${getPythonBin(2)}`, '--dockerizePip=true', 'package']);
528536

529537
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
530538
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
531-
t.false(zipfiles.includes(`boto3${sep}__init__.py`), 'boto3 is NOT packaged');
539+
t.false(
540+
zipfiles.includes(`boto3${sep}__init__.py`),
541+
'boto3 is NOT packaged'
542+
);
532543
t.end();
533544
},
534545
{ skip: !canUseDocker() }
@@ -540,7 +551,12 @@ test(
540551
process.chdir('tests/base');
541552
const path = npm(['pack', '../..']);
542553
npm(['i', path]);
543-
sls([`--pythonBin=${getPythonBin(2)}`, '--dockerizePip=true', '--slim=true', 'package']);
554+
sls([
555+
`--pythonBin=${getPythonBin(2)}`,
556+
'--dockerizePip=true',
557+
'--slim=true',
558+
'package'
559+
]);
544560
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
545561
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
546562
t.deepEqual(
@@ -565,7 +581,12 @@ test(
565581
copySync('_slimPatterns.yml', 'slimPatterns.yml');
566582
const path = npm(['pack', '../..']);
567583
npm(['i', path]);
568-
sls([`--pythonBin=${getPythonBin(2)}`, '--dockerizePip=true', '--slim=true', 'package']);
584+
sls([
585+
`--pythonBin=${getPythonBin(2)}`,
586+
'--dockerizePip=true',
587+
'--slim=true',
588+
'package'
589+
]);
569590
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
570591
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
571592
t.deepEqual(
@@ -649,7 +670,7 @@ test('pipenv py3.6 can package flask with zip option', t => {
649670
t.end();
650671
});
651672

652-
test('pipenv py3.6 doesn\'t package bottle with noDeploy option', t => {
673+
test("pipenv py3.6 doesn't package bottle with noDeploy option", t => {
653674
process.chdir('tests/pipenv');
654675
const path = npm(['pack', '../..']);
655676
npm(['i', path]);
@@ -671,7 +692,9 @@ test('py3.6 can package flask with zip option and no explicit include', t => {
671692
process.chdir('tests/base');
672693
const path = npm(['pack', '../..']);
673694
npm(['i', path]);
674-
sls(['--zip=true', '--include=\'[]\'', 'package']);
695+
perl(['-p', "-i'.bak'", '-e', 's/include://', 'serverless.yml']);
696+
perl(['-p', "-i'.bak'", '-e', 's/^.*handler.py.*$//', 'serverless.yml']);
697+
sls(['--zip=true', 'package']);
675698
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
676699
t.true(
677700
zipfiles.includes('.requirements.zip'),
@@ -683,7 +706,7 @@ test('py3.6 can package flask with zip option and no explicit include', t => {
683706
"flask isn't packaged on its own"
684707
);
685708
t.end();
686-
}, { skip: true });
709+
});
687710

688711
test('py3.6 can package lambda-decorators using vendor option', t => {
689712
process.chdir('tests/base');
@@ -692,7 +715,10 @@ test('py3.6 can package lambda-decorators using vendor option', t => {
692715
sls([`--vendor=./vendor`, 'package']);
693716
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
694717
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
695-
t.true(zipfiles.includes(`lambda_decorators.py`), 'lambda_decorators.py is packaged');
718+
t.true(
719+
zipfiles.includes(`lambda_decorators.py`),
720+
'lambda_decorators.py is packaged'
721+
);
696722
t.false(zipfiles.includes(`boto3${sep}__init__.py`), 'boto3 is NOT packaged');
697723
t.end();
698724
});
@@ -703,26 +729,43 @@ test(
703729
process.chdir('tests/base');
704730
const path = npm(['pack', '../..']);
705731
const perm = '775';
706-
writeFileSync(`foobar`, '', { mode: perm });
707732

708733
npm(['i', path]);
709-
sls(['--include=\'[handler.py, foobar]\'', '--vendor=./vendor', 'package']);
734+
perl([
735+
'-p',
736+
"-i'.bak'",
737+
'-e',
738+
's/(handler.py.*$)/$1\n - foobar/',
739+
'serverless.yml'
740+
]);
741+
writeFileSync(`foobar`, '', { mode: perm });
742+
sls(['--vendor=./vendor', 'package']);
710743

711744
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
712745
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
713-
t.true(zipfiles.includes(`lambda_decorators.py`), 'lambda_decorators.py is packaged');
714-
t.false(zipfiles.includes(`boto3${sep}__init__.py`), 'boto3 is NOT packaged');
746+
t.true(
747+
zipfiles.includes(`lambda_decorators.py`),
748+
'lambda_decorators.py is packaged'
749+
);
750+
t.true(zipfiles.includes(`foobar`), 'foobar is packaged');
751+
t.false(
752+
zipfiles.includes(`boto3${sep}__init__.py`),
753+
'boto3 is NOT packaged'
754+
);
715755

756+
const zipfiles_with_metadata = listZipFilesWithMetaData(
757+
'.serverless/sls-py-req-test.zip'
758+
);
716759
t.true(
717-
zipfiles['foobar'].unixPermissions
760+
zipfiles_with_metadata['foobar'].unixPermissions
718761
.toString(8)
719762
.slice(3, 6) === perm,
720763
'foobar has retained its executable file permissions'
721764
);
722765

723766
t.end();
724767
},
725-
{ skip: true || process.platform === 'win32' }
768+
{ skip: process.platform === 'win32' }
726769
);
727770

728771
test('py3.6 can package flask in a project with a space in it', t => {
@@ -737,18 +780,24 @@ test('py3.6 can package flask in a project with a space in it', t => {
737780
t.end();
738781
});
739782

740-
test('py3.6 can package flask in a project with a space in it with docker', t => {
741-
copySync('tests/base', 'tests/base with a space');
742-
process.chdir('tests/base with a space');
743-
const path = npm(['pack', '../..']);
744-
npm(['i', path]);
745-
sls(['--dockerizePip=true', 'package']);
746-
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
747-
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
748-
t.false(zipfiles.includes(`boto3${sep}__init__.py`), 'boto3 is NOT packaged');
749-
t.end();
750-
},
751-
{ skip: !canUseDocker() });
783+
test(
784+
'py3.6 can package flask in a project with a space in it with docker',
785+
t => {
786+
copySync('tests/base', 'tests/base with a space');
787+
process.chdir('tests/base with a space');
788+
const path = npm(['pack', '../..']);
789+
npm(['i', path]);
790+
sls(['--dockerizePip=true', 'package']);
791+
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
792+
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
793+
t.false(
794+
zipfiles.includes(`boto3${sep}__init__.py`),
795+
'boto3 is NOT packaged'
796+
);
797+
t.end();
798+
},
799+
{ skip: !canUseDocker() }
800+
);
752801

753802
test('py3.6 supports custom file name with fileName option', t => {
754803
process.chdir('tests/base');
@@ -757,7 +806,10 @@ test('py3.6 supports custom file name with fileName option', t => {
757806
npm(['i', path]);
758807
sls(['--fileName=puck', 'package']);
759808
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
760-
t.true(zipfiles.includes(`requests${sep}__init__.py`), 'requests is packaged');
809+
t.true(
810+
zipfiles.includes(`requests${sep}__init__.py`),
811+
'requests is packaged'
812+
);
761813
t.false(zipfiles.includes(`flask${sep}__init__.py`), 'flask is NOT packaged');
762814
t.false(zipfiles.includes(`boto3${sep}__init__.py`), 'boto3 is NOT packaged');
763815
t.end();

0 commit comments

Comments
 (0)