|
| 1 | +/* eslint-env jest */ |
| 2 | + |
| 3 | +import { join } from 'path' |
| 4 | +import cheerio from 'cheerio' |
| 5 | +import { renderViaHTTP, findPort, launchApp, killApp } from 'next-test-utils' |
| 6 | + |
| 7 | +jest.setTimeout(1000 * 60 * 2) |
| 8 | + |
| 9 | +const appDir = join(__dirname, '..') |
| 10 | +let appPort |
| 11 | +let app |
| 12 | + |
| 13 | +async function get$(path, query) { |
| 14 | + const html = await renderViaHTTP(appPort, path, query) |
| 15 | + return cheerio.load(html) |
| 16 | +} |
| 17 | + |
| 18 | +describe('TypeScript Features', () => { |
| 19 | + describe('default behavior', () => { |
| 20 | + beforeAll(async () => { |
| 21 | + appPort = await findPort() |
| 22 | + app = await launchApp(appDir, appPort, {}) |
| 23 | + }) |
| 24 | + afterAll(() => killApp(app)) |
| 25 | + |
| 26 | + it('should alias components', async () => { |
| 27 | + const $ = await get$('/basic-alias') |
| 28 | + expect($('body').text()).toMatch(/World/) |
| 29 | + }) |
| 30 | + |
| 31 | + it('should resolve the first item in the array first', async () => { |
| 32 | + const $ = await get$('/resolve-order') |
| 33 | + expect($('body').text()).toMatch(/Hello from a/) |
| 34 | + }) |
| 35 | + |
| 36 | + it('should resolve the second item in as a fallback', async () => { |
| 37 | + const $ = await get$('/resolve-fallback') |
| 38 | + expect($('body').text()).toMatch(/Hello from only b/) |
| 39 | + }) |
| 40 | + |
| 41 | + it('should resolve a single matching alias', async () => { |
| 42 | + const $ = await get$('/single-alias') |
| 43 | + expect($('body').text()).toMatch(/Hello/) |
| 44 | + }) |
| 45 | + |
| 46 | + it('should not resolve to .d.ts files', async () => { |
| 47 | + const $ = await get$('/alias-to-d-ts') |
| 48 | + expect($('body').text()).toMatch(/Not aliased to d\.ts file/) |
| 49 | + }) |
| 50 | + }) |
| 51 | +}) |
0 commit comments