mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
test(es/codegen): Add some tests for sourcemap (#3078)
This commit is contained in:
parent
cdc4676a88
commit
0e5895043f
11
crates/swc/tests/fixture/sourcemap/006/input/.swcrc
Normal file
11
crates/swc/tests/fixture/sourcemap/006/input/.swcrc
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"sourceMaps": true,
|
||||
"inlineSourcesContent": true,
|
||||
"jsc": {
|
||||
"transform": {
|
||||
"hidden": {
|
||||
"jest": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
42
crates/swc/tests/fixture/sourcemap/006/input/index.js
Normal file
42
crates/swc/tests/fixture/sourcemap/006/input/index.js
Normal 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)
|
||||
})
|
97
crates/swc/tests/fixture/sourcemap/006/output/index.js
Normal file
97
crates/swc/tests/fixture/sourcemap/006/output/index.js
Normal 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);
|
||||
})));
|
37
crates/swc/tests/fixture/sourcemap/006/output/index.map
Normal file
37
crates/swc/tests/fixture/sourcemap/006/output/index.map
Normal 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,CAAC,EAADA,CAAC;oBAAEC,CAAC,EAAE,EAAE;gBAA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AAEJ,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
|
||||
}
|
11
crates/swc/tests/fixture/sourcemap/007/input/.swcrc
Normal file
11
crates/swc/tests/fixture/sourcemap/007/input/.swcrc
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"sourceMaps": true,
|
||||
"inlineSourcesContent": true,
|
||||
"jsc": {
|
||||
"transform": {
|
||||
"hidden": {
|
||||
"jest": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
crates/swc/tests/fixture/sourcemap/007/input/index.js
Normal file
9
crates/swc/tests/fixture/sourcemap/007/input/index.js
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Logs some text
|
||||
*/
|
||||
export const LogSomeText = (text) => {
|
||||
console.log(text);
|
||||
console.log(text);
|
||||
console.log(text);
|
||||
console.log(text);
|
||||
};
|
8
crates/swc/tests/fixture/sourcemap/007/output/index.js
Normal file
8
crates/swc/tests/fixture/sourcemap/007/output/index.js
Normal 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);
|
||||
};
|
16
crates/swc/tests/fixture/sourcemap/007/output/index.map
Normal file
16
crates/swc/tests/fixture/sourcemap/007/output/index.map
Normal 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
|
||||
}
|
13
crates/swc/tests/fixture/sourcemap/008/input/.swcrc
Normal file
13
crates/swc/tests/fixture/sourcemap/008/input/.swcrc
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"module": {
|
||||
"type": "commonjs"
|
||||
},
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"tsx": false
|
||||
},
|
||||
"target": "es2016"
|
||||
},
|
||||
"sourceMaps": true
|
||||
}
|
21
crates/swc/tests/fixture/sourcemap/008/input/index.js
Normal file
21
crates/swc/tests/fixture/sourcemap/008/input/index.js
Normal 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);
|
||||
});
|
||||
});
|
17
crates/swc/tests/fixture/sourcemap/008/output/index.js
Normal file
17
crates/swc/tests/fixture/sourcemap/008/output/index.js
Normal 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);
|
||||
});
|
||||
});
|
16
crates/swc/tests/fixture/sourcemap/008/output/index.map
Normal file
16
crates/swc/tests/fixture/sourcemap/008/output/index.map
Normal 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
|
||||
}
|
13
crates/swc/tests/fixture/sourcemap/009/input/.swcrc
Normal file
13
crates/swc/tests/fixture/sourcemap/009/input/.swcrc
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"module": {
|
||||
"type": "commonjs"
|
||||
},
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"tsx": false
|
||||
},
|
||||
"target": "es2016"
|
||||
},
|
||||
"sourceMaps": true
|
||||
}
|
7
crates/swc/tests/fixture/sourcemap/009/input/index.js
Normal file
7
crates/swc/tests/fixture/sourcemap/009/input/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* This is a
|
||||
* long
|
||||
* license
|
||||
* header
|
||||
*/
|
||||
console.log(new Error().stack)
|
7
crates/swc/tests/fixture/sourcemap/009/output/index.js
Normal file
7
crates/swc/tests/fixture/sourcemap/009/output/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
/**
|
||||
* This is a
|
||||
* long
|
||||
* license
|
||||
* header
|
||||
*/ console.log(new Error().stack);
|
16
crates/swc/tests/fixture/sourcemap/009/output/index.map
Normal file
16
crates/swc/tests/fixture/sourcemap/009/output/index.map
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user