Repository: buxlabs/boxwood (js)

Issue:
Add an error when `<script routes>` is used but routes are not provided to compilerOptions

Pull request description:
Better error handling when script[routes] is used but routes are not set up yet
Closes #627 

Patch:
diff --git a/src/plugins/RoutesPlugin.js b/src/plugins/RoutesPlugin.js
index 3749df5..db73893 100644
--- a/src/plugins/RoutesPlugin.js
+++ b/src/plugins/RoutesPlugin.js
@@ -12,8 +12,10 @@ class RoutesPlugin extends Plugin {
   }
 
   prerun ({ tag, keys, fragment }) {
-    if (this.disabled) { return }
     if (tag === 'script' && keys.includes('routes')) {
+      if (this.disabled) {
+        return this.errors.push({ type: 'EMPTY_ROUTES', message: 'You need to set up routes in compiler options.' })
+      }
       const { content } = fragment.children[0]
       // TODO implement routes.has(, routes.each(
       if (content.includes('routes.get(')) {


Test patch:
diff --git a/test/spec/features/routes.spec.js b/test/spec/features/routes.spec.js
new file mode 100644
index 0000000..2da639e
--- /dev/null
+++ b/test/spec/features/routes.spec.js
@@ -0,0 +1,9 @@
+const test = require('ava')
+const compile = require('../../helpers/compile')
+const { escape } = require('../../..')
+
+test('it returns an error when routes are not set and script[routes] is used', async assert => {
+  const { errors } = await compile('<script routes>routes.get("foo.bar")</script>')
+  assert.deepEqual(errors.length, 1)
+  assert.deepEqual(errors[0].type, 'EMPTY_ROUTES')
+})