test(es/codegen): Add some tests for sourcemap (#3078)

This commit is contained in:
Donny/강동윤 2021-12-20 18:26:30 +09:00 committed by GitHub
parent cdc4676a88
commit 0e5895043f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 341 additions and 0 deletions

View File

@ -0,0 +1,11 @@
{
"sourceMaps": true,
"inlineSourcesContent": true,
"jsc": {
"transform": {
"hidden": {
"jest": true
}
}
}
}

View File

@ -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)
})

View File

@ -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);
})));

View File

@ -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,CA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AAO,EAAPA,OAAO;oBAAEd,CAAC,EAADA,CAAC;oBAAEJ,IAAI,EAAJA,IAAI;oBAAEC,IAAI,EAAJA,IAAI;oBAAEC,IAAI,EAAJA,IAAI;gBAAC,CAAC;gBAE5CQ,MAAM,CAACT,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
}

View File

@ -0,0 +1,11 @@
{
"sourceMaps": true,
"inlineSourcesContent": true,
"jsc": {
"transform": {
"hidden": {
"jest": true
}
}
}
}

View File

@ -0,0 +1,9 @@
/**
* Logs some text
*/
export const LogSomeText = (text) => {
console.log(text);
console.log(text);
console.log(text);
console.log(text);
};

View File

@ -0,0 +1,8 @@
/**
* Logs some text
*/ export var LogSomeText = function(text) {
console.log(text);
console.log(text);
console.log(text);
console.log(text);
};

View File

@ -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
}

View File

@ -0,0 +1,13 @@
{
"module": {
"type": "commonjs"
},
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false
},
"target": "es2016"
},
"sourceMaps": true
}

View File

@ -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);
});
});

View File

@ -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);
});
});

View File

@ -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
}

View File

@ -0,0 +1,13 @@
{
"module": {
"type": "commonjs"
},
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false
},
"target": "es2016"
},
"sourceMaps": true
}

View File

@ -0,0 +1,7 @@
/**
* This is a
* long
* license
* header
*/
console.log(new Error().stack)

View File

@ -0,0 +1,7 @@
"use strict";
/**
* This is a
* long
* license
* header
*/ console.log(new Error().stack);

View File

@ -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
}