-
-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dev-server-esbuild): accept banner/footer setting to esbuild tra…
…nsformer (#2056)
- Loading branch information
Showing
4 changed files
with
83 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,5 @@ | ||
--- | ||
'@web/dev-server-esbuild': minor | ||
--- | ||
|
||
Expose banner/footer as a pass-through to esbuild transform |
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
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
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,70 @@ | ||
import { expect } from 'chai'; | ||
import fetch from 'node-fetch'; | ||
import { createTestServer } from '@web/dev-server-core/test-helpers'; | ||
import { expectIncludes } from '@web/dev-server-core/test-helpers'; | ||
|
||
import { esbuildPlugin } from '../src/index'; | ||
|
||
describe('esbuildPlugin banner/footers', function () { | ||
this.timeout(5000); | ||
|
||
it('prepends custom banner', async () => { | ||
const { server, host } = await createTestServer({ | ||
rootDir: __dirname, | ||
plugins: [ | ||
{ | ||
name: 'test', | ||
serve(context) { | ||
if (context.path === '/foo.ts') { | ||
return `export const foo = 5;`; | ||
} | ||
}, | ||
}, | ||
esbuildPlugin({ ts: true, banner: '/* hello there */' }), | ||
], | ||
}); | ||
|
||
try { | ||
const response = await fetch(`${host}/foo.ts`); | ||
const text = await response.text(); | ||
|
||
const indexOfExpr = text.indexOf('export const foo = 5;'); | ||
const indexOfBanner = text.indexOf('/* hello there */'); | ||
|
||
expectIncludes(text, '/* hello there */'); | ||
expect(indexOfExpr).to.be.greaterThan(indexOfBanner); | ||
} finally { | ||
server.stop(); | ||
} | ||
}); | ||
|
||
it('appends custom footer', async () => { | ||
const { server, host } = await createTestServer({ | ||
rootDir: __dirname, | ||
plugins: [ | ||
{ | ||
name: 'test', | ||
serve(context) { | ||
if (context.path === '/foo.ts') { | ||
return `export const foo = 5;`; | ||
} | ||
}, | ||
}, | ||
esbuildPlugin({ ts: true, footer: '/* hello there */' }), | ||
], | ||
}); | ||
|
||
try { | ||
const response = await fetch(`${host}/foo.ts`); | ||
const text = await response.text(); | ||
|
||
const indexOfExpr = text.indexOf('export const foo = 5;'); | ||
const indexOfFooter = text.indexOf('/* hello there */'); | ||
|
||
expectIncludes(text, '/* hello there */'); | ||
expect(indexOfFooter).to.be.greaterThan(indexOfExpr); | ||
} finally { | ||
server.stop(); | ||
} | ||
}); | ||
}); |