Skip to content

Commit

Permalink
guard against missing semicolons in import statements
Browse files Browse the repository at this point in the history
  • Loading branch information
jonfriskics committed May 15, 2018
1 parent 3817b43 commit 9eaf2c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ describe('BookList.vue', () => {
const script = nodes.filter(node => node.nodeName === 'script');

// Test for correct import statement
const ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' });

let ast
try {
ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' });
} catch (e) {
assert(false, "It looks like your import statement is missing a semicolon at the end.")
}

let results = esquery(ast, 'ImportDeclaration[source.value="./BookItem"]');
assert(results.length > 0, 'The `BookItem` class was not imported from `./BookItem` In BookList.vue');

Expand Down
8 changes: 7 additions & 1 deletion test/unit/mocha/part4/book-list-contains-book-item.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ describe('BookList.vue', () => {
const script = nodes.filter(node => node.nodeName === 'script');

// Test for bookList definition in the component key
const ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' });
let ast
try {
ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' });
} catch (e) {
assert(false, "It looks like your import statement is missing a semicolon at the end.")
}

const results = esquery(ast, 'Property[key.name=components] > ObjectExpression > Property[key.name=BookItem]');
assert(results.length > 0, 'The value of the `components` property is not an object containing `BookItem` in BookList.vue');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ describe('BookList.vue', () => {
assert(false, "We either didn't find a script tag, or any code in a script tag in the BookForm component.")
}

const ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' });
let ast
try {
ast = esprima.parse(script[0].childNodes[0].value, { sourceType: 'module' });
} catch (e) {
assert(false, "Something went wrong and we weren't able to check your code.")
}

const methods = esquery(ast, 'Property[key.name=methods]');
assert(methods.length > 0, 'The BookList\'s `methods` declaration is not present');
});
Expand Down

0 comments on commit 9eaf2c3

Please sign in to comment.