Skip to content

Commit c88f7e5

Browse files
dschepbweigel
authored and
bweigel
committed
test for zip + noDeploy. serverless#186
1 parent 411ced4 commit c88f7e5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test.js

+34
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const mkCommand = cmd => (args, options = {}) => {
3636
const sls = mkCommand('sls');
3737
const git = mkCommand('git');
3838
const npm = mkCommand('npm');
39+
const perl = mkCommand('perl');
3940

4041
const setup = () => {
4142
removeSync(getUserCachePath());
@@ -81,6 +82,12 @@ const getPythonBin = (version = 3) => {
8182

8283
const listZipFiles = filename =>
8384
Object.keys(deasync(new JSZip().loadAsync(readFileSync(filename))).files);
85+
const listRequirementsZipFiles = filename => {
86+
const zip = deasync(new JSZip().loadAsync(readFileSync(filename)));
87+
const reqsBuffer = deasync(zip.file('.requirements.zip').async('nodebuffer'));
88+
const reqsZip = deasync(new JSZip().loadAsync(reqsBuffer));
89+
return Object.keys(reqsZip.files)
90+
};
8491

8592
test('default pythonBin can package flask with default options', t => {
8693
process.chdir('tests/base');
@@ -134,3 +141,30 @@ test('py3.6 can package flask with slim option', t => {
134141
);
135142
t.end();
136143
});
144+
145+
146+
/*
147+
* News tests not in test.bats
148+
*/
149+
150+
test("py3.6 doesn't package bottle with zip option", t => {
151+
process.chdir('tests/base');
152+
const path = npm(['pack', '../..']);
153+
npm(['i', path]);
154+
perl(['-p', "-i'.bak'", '-e', 's/(pythonRequirements:$)/\\1\\n noDeploy: [bottle]/', 'serverless.yml'])
155+
sls([`--pythonBin=${getPythonBin(3)}`, '--zip=true', 'package']);
156+
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
157+
const zippedReqs = listRequirementsZipFiles('.serverless/sls-py-req-test.zip');
158+
t.true(
159+
zipfiles.includes('.requirements.zip'),
160+
'zipped requirements are packaged'
161+
);
162+
t.true(zipfiles.includes(`unzip_requirements.py`), 'unzip util is packaged');
163+
t.false(
164+
zipfiles.includes(`flask${sep}__init__.py`),
165+
"flask isn't packaged on its own"
166+
);
167+
t.true(zippedReqs.includes(`flask${sep}__init__.py`), 'flask is packaged in the .requirements.zip file');
168+
t.false(zippedReqs.includes(`bottle.py`), 'bottle is not packaged in the .requirements.zip file');
169+
t.end();
170+
});

0 commit comments

Comments
 (0)