-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(es/codegen): Add some tests for sourcemap (#3078)
- Loading branch information
Showing
16 changed files
with
341 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"sourceMaps": true, | ||
"inlineSourcesContent": true, | ||
"jsc": { | ||
"transform": { | ||
"hidden": { | ||
"jest": true | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
it('should compress avif smaller than webp and smaller than jpg', async () => { | ||
|
||
/** | ||
* | ||
* 'Foo bar baz' | ||
* | ||
* Return @ | ||
*/ | ||
const query = { url: '/test.jpg', w, q: 75 } | ||
const res1 = await fetchViaHTTP(appPort, '/_next/image', query, { | ||
headers: { | ||
accept: 'image/avif', | ||
}, | ||
}) | ||
expect(res1.status).toBe(200) | ||
expect(res1.headers.get('Content-Type')).toBe('image/avif') | ||
|
||
const res2 = await fetchViaHTTP(appPort, '/_next/image', query, { | ||
headers: { | ||
accept: 'image/webp', | ||
}, | ||
}) | ||
expect(res2.status).toBe(200) | ||
expect(res2.headers.get('Content-Type')).toBe('image/webp') | ||
|
||
const res3 = await fetchViaHTTP(appPort, '/_next/image', query, { | ||
headers: { | ||
accept: 'image/jpeg', | ||
}, | ||
}) | ||
expect(res3.status).toBe(200) | ||
expect(res3.headers.get('Content-Type')).toBe('image/jpeg') | ||
|
||
const avif = (await res1.buffer()).byteLength | ||
const webp = (await res2.buffer()).byteLength | ||
const jpeg = (await res3.buffer()).byteLength | ||
|
||
console.log({ isSharp, w, avif, webp, jpeg }) | ||
|
||
expect(webp).toBeLessThan(jpeg) | ||
expect(avif).toBeLessThan(webp) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import regeneratorRuntime from "regenerator-runtime"; | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function() { | ||
var self = this, args = arguments; | ||
return new Promise(function(resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
it('should compress avif smaller than webp and smaller than jpg', _asyncToGenerator(regeneratorRuntime.mark(function _callee() { | ||
var query, res1, res2, res3, avif, webp, jpeg; | ||
return regeneratorRuntime.wrap(function _callee$(_ctx) { | ||
while(1)switch(_ctx.prev = _ctx.next){ | ||
case 0: | ||
query = { | ||
url: '/test.jpg', | ||
w: w, | ||
q: 75 | ||
}; | ||
_ctx.next = 3; | ||
return fetchViaHTTP(appPort, '/_next/image', query, { | ||
headers: { | ||
accept: 'image/avif' | ||
} | ||
}); | ||
case 3: | ||
res1 = _ctx.sent; | ||
expect(res1.status).toBe(200); | ||
expect(res1.headers.get('Content-Type')).toBe('image/avif'); | ||
_ctx.next = 8; | ||
return fetchViaHTTP(appPort, '/_next/image', query, { | ||
headers: { | ||
accept: 'image/webp' | ||
} | ||
}); | ||
case 8: | ||
res2 = _ctx.sent; | ||
expect(res2.status).toBe(200); | ||
expect(res2.headers.get('Content-Type')).toBe('image/webp'); | ||
_ctx.next = 13; | ||
return fetchViaHTTP(appPort, '/_next/image', query, { | ||
headers: { | ||
accept: 'image/jpeg' | ||
} | ||
}); | ||
case 13: | ||
res3 = _ctx.sent; | ||
expect(res3.status).toBe(200); | ||
expect(res3.headers.get('Content-Type')).toBe('image/jpeg'); | ||
_ctx.next = 18; | ||
return res1.buffer(); | ||
case 18: | ||
avif = _ctx.sent.byteLength; | ||
_ctx.next = 21; | ||
return res2.buffer(); | ||
case 21: | ||
webp = _ctx.sent.byteLength; | ||
_ctx.next = 24; | ||
return res3.buffer(); | ||
case 24: | ||
jpeg = _ctx.sent.byteLength; | ||
console.log({ | ||
isSharp: isSharp, | ||
w: w, | ||
avif: avif, | ||
webp: webp, | ||
jpeg: jpeg | ||
}); | ||
expect(webp).toBeLessThan(jpeg); | ||
expect(avif).toBeLessThan(webp); | ||
case 28: | ||
case "end": | ||
return _ctx.stop(); | ||
} | ||
}, _callee); | ||
}))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAAA,EAAE,CAAC,CAA6D,wGAAE,QAAQ,WAAI,CAAC;QAQrEC,KAAK,EACLC,IAAI,EAQJC,IAAI,EAQJC,IAAI,EAQJC,IAAI,EACJC,IAAI,EACJC,IAAI;;;;gBA3BJN,KAAK,GAAG,CAAC;oBAACO,GAAG,EAAE,CAAW;oBAAEC,CAAC,EAADA,CAAC;oBAAEC,CAAC,EAAE,EAAE;gBAAC,CAAC;;uBACzBC,YAAY,CAACC,OAAO,EAAE,CAAc,eAAEX,KAAK,EAAE,CAAC;oBAC7DY,OAAO,EAAE,CAAC;wBACNC,MAAM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AACT,IAAI,EAAEkB,YAAY,CAACjB,IAAI;gBAC9BQ,MAAM,CAACV,IAAI,EAAEmB,YAAY,CAAClB,IAAI;;;;;;AAClC,CAAC", | ||
"names": [ | ||
"it", | ||
"query", | ||
"res1", | ||
"res2", | ||
"res3", | ||
"avif", | ||
"webp", | ||
"jpeg", | ||
"url", | ||
"w", | ||
"q", | ||
"fetchViaHTTP", | ||
"appPort", | ||
"headers", | ||
"accept", | ||
"expect", | ||
"status", | ||
"toBe", | ||
"get", | ||
"buffer", | ||
"byteLength", | ||
"console", | ||
"log", | ||
"isSharp", | ||
"toBeLessThan" | ||
], | ||
"sources": [ | ||
"../../input/index.js" | ||
], | ||
"sourcesContent": [ | ||
"it('should compress avif smaller than webp and smaller than jpg', async () => {\n\n /**\n * \n * 'Foo bar baz'\n * \n * Return @\n */\n const query = { url: '/test.jpg', w, q: 75 }\n const res1 = await fetchViaHTTP(appPort, '/_next/image', query, {\n headers: {\n accept: 'image/avif',\n },\n })\n expect(res1.status).toBe(200)\n expect(res1.headers.get('Content-Type')).toBe('image/avif')\n\n const res2 = await fetchViaHTTP(appPort, '/_next/image', query, {\n headers: {\n accept: 'image/webp',\n },\n })\n expect(res2.status).toBe(200)\n expect(res2.headers.get('Content-Type')).toBe('image/webp')\n\n const res3 = await fetchViaHTTP(appPort, '/_next/image', query, {\n headers: {\n accept: 'image/jpeg',\n },\n })\n expect(res3.status).toBe(200)\n expect(res3.headers.get('Content-Type')).toBe('image/jpeg')\n\n const avif = (await res1.buffer()).byteLength\n const webp = (await res2.buffer()).byteLength\n const jpeg = (await res3.buffer()).byteLength\n\n console.log({ isSharp, w, avif, webp, jpeg })\n\n expect(webp).toBeLessThan(jpeg)\n expect(avif).toBeLessThan(webp)\n})" | ||
], | ||
"version": 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"sourceMaps": true, | ||
"inlineSourcesContent": true, | ||
"jsc": { | ||
"transform": { | ||
"hidden": { | ||
"jest": true | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Logs some text | ||
*/ | ||
export const LogSomeText = (text) => { | ||
console.log(text); | ||
console.log(text); | ||
console.log(text); | ||
console.log(text); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Logs some text | ||
*/ export var LogSomeText = function(text) { | ||
console.log(text); | ||
console.log(text); | ||
console.log(text); | ||
console.log(text); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"mappings": "AAAA,EAEG,AAFH;;CAEG,AAFH,EAEG,CACH,MAAM,CAAC,GAAK,CAACA,WAAW,GAAG,QAAQ,CAAPC,IAAI,EAAK,CAAC;IAClCC,OAAO,CAACC,GAAG,CAACF,IAAI;IAChBC,OAAO,CAACC,GAAG,CAACF,IAAI;IAChBC,OAAO,CAACC,GAAG,CAACF,IAAI;IAChBC,OAAO,CAACC,GAAG,CAACF,IAAI;AACpB,CAAC", | ||
"names": [ | ||
"LogSomeText", | ||
"text", | ||
"console", | ||
"log" | ||
], | ||
"sources": [ | ||
"../../input/index.js" | ||
], | ||
"sourcesContent": [ | ||
"/**\n * Logs some text\n */\nexport const LogSomeText = (text) => {\n console.log(text);\n console.log(text);\n console.log(text);\n console.log(text);\n};" | ||
], | ||
"version": 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"module": { | ||
"type": "commonjs" | ||
}, | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": false | ||
}, | ||
"target": "es2016" | ||
}, | ||
"sourceMaps": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
describe("multiline comments", () => { | ||
it("test1", () => { | ||
expect(false).toBe(true); | ||
}); | ||
|
||
it("test2", () => { | ||
/**/ | ||
expect(false).toBe(true); | ||
}); | ||
|
||
it("test3", () => { | ||
/* | ||
* | ||
*/ | ||
expect(false).toBe(true); | ||
}); | ||
|
||
it("test4", () => { | ||
expect(false).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use strict"; | ||
describe("multiline comments", ()=>{ | ||
it("test1", ()=>{ | ||
expect(false).toBe(true); | ||
}); | ||
it("test2", ()=>{ | ||
/**/ expect(false).toBe(true); | ||
}); | ||
it("test3", ()=>{ | ||
/* | ||
* | ||
*/ expect(false).toBe(true); | ||
}); | ||
it("test4", ()=>{ | ||
expect(false).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"mappings": ";AAAAA,QAAQ,CAAC,CAAoB,yBAAQ,CAAC;IAClCC,EAAE,CAAC,CAAO,YAAQ,CAAC;QACfC,MAAM,CAAC,KAAK,EAAEC,IAAI,CAAC,IAAI;IAC3B,CAAC;IAEDF,EAAE,CAAC,CAAO,YAAQ,CAAC;QACf,EAAI,AAAJ,EAAI,CACJC,MAAM,CAAC,KAAK,EAAEC,IAAI,CAAC,IAAI;IAC3B,CAAC;IAEDF,EAAE,CAAC,CAAO,YAAQ,CAAC;QACf,EAEG,AAFH;;SAEG,AAFH,EAEG,CACHC,MAAM,CAAC,KAAK,EAAEC,IAAI,CAAC,IAAI;IAC3B,CAAC;IAEDF,EAAE,CAAC,CAAO,YAAQ,CAAC;QACfC,MAAM,CAAC,KAAK,EAAEC,IAAI,CAAC,IAAI;IAC3B,CAAC;AACL,CAAC", | ||
"names": [ | ||
"describe", | ||
"it", | ||
"expect", | ||
"toBe" | ||
], | ||
"sources": [ | ||
"../../input/index.js" | ||
], | ||
"sourcesContent": [ | ||
"describe(\"multiline comments\", () => {\n it(\"test1\", () => {\n expect(false).toBe(true);\n });\n\n it(\"test2\", () => {\n /**/\n expect(false).toBe(true);\n });\n\n it(\"test3\", () => {\n /*\n *\n */\n expect(false).toBe(true);\n });\n\n it(\"test4\", () => {\n expect(false).toBe(true);\n });\n});" | ||
], | ||
"version": 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"module": { | ||
"type": "commonjs" | ||
}, | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": false | ||
}, | ||
"target": "es2016" | ||
}, | ||
"sourceMaps": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* This is a | ||
* long | ||
* license | ||
* header | ||
*/ | ||
console.log(new Error().stack) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
/** | ||
* This is a | ||
* long | ||
* license | ||
* header | ||
*/ console.log(new Error().stack); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"mappings": ";AAAA,EAKG,AALH;;;;;CAKG,AALH,EAKG,CACHA,OAAO,CAACC,GAAG,CAAC,GAAG,CAACC,KAAK,GAAGC,KAAK", | ||
"names": [ | ||
"console", | ||
"log", | ||
"Error", | ||
"stack" | ||
], | ||
"sources": [ | ||
"../../input/index.js" | ||
], | ||
"sourcesContent": [ | ||
"/**\n * This is a\n * long\n * license\n * header\n */\nconsole.log(new Error().stack)" | ||
], | ||
"version": 3 | ||
} |
0e58950
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
full_es2015
219464200
ns/iter (± 21880249
)202218915
ns/iter (± 20038138
)1.09
full_es2016
179589828
ns/iter (± 10508239
)165260587
ns/iter (± 35946316
)1.09
full_es2017
184205765
ns/iter (± 9608292
)175935158
ns/iter (± 38623044
)1.05
full_es2018
181658220
ns/iter (± 9312635
)185079617
ns/iter (± 31448615
)0.98
full_es2019
179179164
ns/iter (± 15196640
)179350358
ns/iter (± 35105434
)1.00
full_es2020
180024765
ns/iter (± 11442955
)180676467
ns/iter (± 30773038
)1.00
full_es3
239101098
ns/iter (± 13743646
)239361661
ns/iter (± 42752730
)1.00
full_es5
236166528
ns/iter (± 20449229
)228263804
ns/iter (± 46459462
)1.03
parser
812348
ns/iter (± 20158
)805097
ns/iter (± 172373
)1.01
This comment was automatically generated by workflow using github-action-benchmark.