-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Watch previous files if preprocessing failed
- Loading branch information
Maximiliano Ruani
committed
Jun 1, 2022
1 parent
6968e89
commit 9ec1e56
Showing
5 changed files
with
112 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Test from "./external-styles.svelte"; | ||
|
||
new Test({ | ||
target: document.body, | ||
}); |
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,7 @@ | ||
<style lang="scss"> | ||
@import "./external.scss"; | ||
</style> | ||
|
||
<div> | ||
<h1>Hello World</h1> | ||
</div> |
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 @@ | ||
p { color: red; } |
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,75 @@ | ||
import { test } from "uvu"; | ||
import * as assert from "uvu/assert"; | ||
import { writeFileSync } from "fs"; | ||
import { fileURLToPath } from "url"; | ||
import { dirname } from "path"; | ||
import { build as _build } from "esbuild"; | ||
import { sass } from "svelte-preprocess-sass"; | ||
import sveltePlugin from "../dist/index.mjs"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
test("Watch and build while preprocess of external dependency succeed and fails", async () => { | ||
|
||
function _createDeferred() { | ||
let resolve = null; | ||
let reject = null; | ||
const promise = new Promise((_resolve, _reject) => { | ||
resolve = _resolve; | ||
reject = _reject; | ||
}); | ||
promise.forceResolve = resolve; | ||
promise.forceReject = reject; | ||
return promise; | ||
} | ||
|
||
let count = 0; | ||
const firstRebuild = _createDeferred(); | ||
const secondRebuild = _createDeferred(); | ||
|
||
//more advanced | ||
const results = await _build({ | ||
entryPoints: ["./test/fixtures/watch-preprocessing/entry.js"], | ||
outdir: "../example/dist", | ||
format: "esm", | ||
minify: true, | ||
bundle: true, | ||
splitting: true, | ||
write: false, //Don't write anywhere | ||
sourcemap: "inline", | ||
plugins: [ | ||
sveltePlugin({ | ||
preprocess: { | ||
style: sass(), | ||
}, | ||
}), | ||
], | ||
watch: { | ||
onRebuild(err, result) { | ||
count++; | ||
if (count === 1) { | ||
firstRebuild.forceResolve(err); | ||
} | ||
else if (count === 2) { | ||
secondRebuild.forceResolve(result); | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
// write external scss with invalid syntax | ||
writeFileSync(`${__dirname}/fixtures/watch-preprocessing/external.scss`, 'p { color: red; }!$%^&*()@$%^@@'); | ||
const firstRebuildResult = await firstRebuild; | ||
assert.ok(firstRebuildResult instanceof Error, 'First build did not fail'); | ||
|
||
// write external scss with valid syntax again | ||
writeFileSync(`${__dirname}/fixtures/watch-preprocessing/external.scss`, 'p { color: red; }'); | ||
const secondRebuildResult = await secondRebuild; | ||
assert.ok(secondRebuildResult.errors.length === 0, "Second build fail"); | ||
|
||
// stop watching | ||
results.stop(); | ||
}); | ||
|
||
test.run(); |