Files
tuono/packages/lazy-fn-vite-plugin/test/transpileSource.test.ts
T
Valerio Ageno f37cb701b3 Create babel plugin to handle lazy loading (#4)
* feat: create babel plugin to handle lazy loading

* fix: update typescript CI to also run the tests in the pipelines

* doc: update lazy loading component inline documentation

* fix: typescript pipeline

* fix: update CI typescript test command

* fix: prevent duplicate pipelines on PR

* feat: create separate vite plugin package

* chore: refined lazy fn package

* test: add test to lazy fn plugin

* feat: update version to v0.1.5
2024-06-20 19:40:14 +02:00

35 lines
1.1 KiB
TypeScript

import { it, expect, describe } from 'vitest'
import { LazyLoadingPlugin } from '../src'
const SOURCE_CODE = `
import { createRoute, lazy } from 'tuono'
const IndexImport = lazy(() => import('./../src/routes/index'))
const PokemonspokemonImport = lazy(
() => import('./../src/routes/pokemons/[pokemon]'),
)
`
const CLIENT_RESULT = `import { lazy } from "react";
import { createRoute } from 'tuono';
const IndexImport = lazy(() => import('./../src/routes/index'));
const PokemonspokemonImport = lazy(() => import('./../src/routes/pokemons/[pokemon]'));`
const SERVER_RESULT = `import { createRoute } from 'tuono';
import IndexImport from "./../src/routes/index";
import PokemonspokemonImport from "./../src/routes/pokemons/[pokemon]";`
describe('Transpile tuono source', () => {
it('Into the client bundle', () => {
const bundle = LazyLoadingPlugin().transform?.(SOURCE_CODE, 'id')
expect(bundle).toBe(CLIENT_RESULT)
})
it('Into the server bundle', () => {
const bundle = LazyLoadingPlugin().transform?.(SOURCE_CODE, 'id', {
ssr: true,
})
expect(bundle).toBe(SERVER_RESULT)
})
})