Skip to content

Commit

Permalink
fix: respect empty values for transform tasks without props
Browse files Browse the repository at this point in the history
  • Loading branch information
velveteer committed Jul 19, 2018
1 parent 7833f54 commit 4b4f9a6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"build": "gulp build",
"build:main": "gulp typescript:main",
"build:module": "gulp typescript:module",
"build:browser": "gulp rollup",
"build:browser": "gulp build:rollup",
"lint": "tslint --project . src/**/*.ts",
"prism:mock": "node test/prism.js",
"prism:record": "node test/prism.js --record",
Expand Down
35 changes: 35 additions & 0 deletions src/lib/api/transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('transform', () => {
polaroid: true,
flip: false,
flop: true,
compress: false,
};

const result = transform(url, testConfig);
Expand Down Expand Up @@ -231,4 +232,38 @@ describe('transform', () => {
assert.equal(result, expected);
});
});

describe('cache', () => {
it('should construct valid parameters', () => {
const testConfig = {
cache: false,
};

const result = transform(url, testConfig);
const expected = `${cdnUrl}/cache=false/${url}`;
assert.equal(result, expected);

const testConfig2 = {
cache: {
expiry: 12345,
},
};

const result2 = transform(url, testConfig2);
const expected2 = `${cdnUrl}/cache=expiry:12345/${url}`;
assert.equal(result2, expected2);
});
});

describe('compress', () => {
it('should construct valid parameters', () => {
const testConfig = {
compress: true,
};

const result = transform(url, testConfig);
const expected = `${cdnUrl}/compress/${url}`;
assert.equal(result, expected);
});
});
});
6 changes: 3 additions & 3 deletions src/lib/api/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,12 @@ const optionToString = (key: string, values: any): string => {

// if we just want to enable feature
if (typeof values === 'boolean') {
if (values === undefined) {
return '';
if (!values && key === 'cache') {
return `${key}=false`;
}

if (!values) {
return `${key}=false`;
return '';
}

return key;
Expand Down

0 comments on commit 4b4f9a6

Please sign in to comment.