-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: throw on rebuild error in local dev
- Loading branch information
Showing
3 changed files
with
196 additions
and
164 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,57 @@ | ||
const test = require('ava') | ||
const fs = require('fs-extra') | ||
const Maizzle = require('../src') | ||
|
||
test.beforeEach(t => { | ||
t.context.folder = '_temp_' + Math.random().toString(36).slice(2, 9) | ||
t.context.log = console.log() | ||
}) | ||
|
||
test.afterEach.always(async t => { | ||
if (t.context.folder) { | ||
await fs.remove(t.context.folder) | ||
delete t.context.folder | ||
} | ||
}) | ||
|
||
test('throws if it cannot spin up local development server', async t => { | ||
// Should throw because there are no template sources in `build.templates` | ||
await t.throwsAsync(async () => { | ||
await Maizzle.serve('local', {}) | ||
}, {instanceOf: Error}) | ||
}) | ||
|
||
test('local server does not compile unwanted file types', async t => { | ||
await Maizzle.serve('local', { | ||
build: { | ||
console: { | ||
clear: true | ||
}, | ||
browsersync: { | ||
ui: false | ||
}, | ||
templates: { | ||
source: 'test/stubs/templates', | ||
destination: { | ||
path: `${t.context.folder}` | ||
} | ||
} | ||
}, | ||
events: { | ||
beforeCreate(config) { | ||
config.foo = 'bar' | ||
} | ||
} | ||
}) | ||
|
||
t.true(await fs.pathExists(`${t.context.folder}`)) | ||
t.true(await fs.pathExists(`${t.context.folder}/2.test`)) | ||
|
||
// Tests watching changes to files | ||
await fs.outputFile('test/stubs/templates/2.html', '<div class="inline">html modified</div>') | ||
t.is(await fs.readFile('test/stubs/templates/2.html', 'utf8'), '<div class="inline">html modified</div>') | ||
|
||
// Don't trigger rebuilds on files not in `filetypes` | ||
await fs.outputFile('test/stubs/templates/2.test', 'test') | ||
t.is(await fs.readFile('test/stubs/templates/2.test', 'utf8'), 'test') | ||
}) |
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