-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prevent fouc in development (#12)
* feat: prevent fouc in development * fix: test failing on windows
- Loading branch information
1 parent
b8dc984
commit 15bef87
Showing
8 changed files
with
295 additions
and
81 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
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
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,46 @@ | ||
/* | ||
* @adonisjs/vite | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { getActiveTest } from '@japa/runner' | ||
|
||
import { Vite } from '../../index.js' | ||
import { ViteOptions } from '../../src/types.js' | ||
import { InlineConfig } from 'vite' | ||
|
||
export const BASE_URL = new URL('./../__app/', import.meta.url) | ||
|
||
/** | ||
* Create an instance of AdonisJS Vite class, run the dev server | ||
* and auto close it when the test ends | ||
*/ | ||
export async function createVite(config: ViteOptions, viteConfig: InlineConfig = {}) { | ||
const test = getActiveTest() | ||
if (!test) { | ||
throw new Error('Cannot create vite instance outside of a test') | ||
} | ||
|
||
/** | ||
* Create a dummy file to ensure the root directory exists | ||
* otherwise Vite will throw an error | ||
*/ | ||
await test.context.fs.create('dummy.txt', 'dummy') | ||
|
||
const vite = new Vite(true, config) | ||
|
||
await vite.createDevServer({ | ||
logLevel: 'silent', | ||
clearScreen: false, | ||
root: test.context.fs.basePath, | ||
...viteConfig, | ||
}) | ||
|
||
test.cleanup(() => vite.stopDevServer()) | ||
|
||
return vite | ||
} |
Oops, something went wrong.