|
| 1 | +const Test = require('../test'); |
| 2 | +const ExecuteCommand = require('../../tasks/execute-command'); |
| 3 | +const path = require('path'); |
| 4 | +const fs = require('fs'); |
| 5 | + |
| 6 | +class AuBuildDoesNotThrowCommandLineErrors extends Test { |
| 7 | + constructor() { |
| 8 | + super('au build does not throw commandline errors'); |
| 9 | + } |
| 10 | + |
| 11 | + onOutput(message) { |
| 12 | + this.debug(message); |
| 13 | + |
| 14 | + if (message.toLowerCase().indexOf('error') > -1) { |
| 15 | + this.executeCommand.stop(); |
| 16 | + this.fail(); |
| 17 | + } else if (isBuildCompletedMessage(message)) { |
| 18 | + this.success(); |
| 19 | + this.executeCommand.stop(); |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + execute() { |
| 24 | + this.executeCommand = new ExecuteCommand('au', ['build'], (msg) => this.onOutput(msg)); |
| 25 | + return this.executeCommand.executeAsNodeScript(); |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +class AuBuildStartsWebpackInWatchMode extends Test { |
| 30 | + constructor(fileToChange) { |
| 31 | + super('au build --watch starts webpack in watch mode'); |
| 32 | + |
| 33 | + this.fileToChange = fileToChange || path.join('src', 'app.html'); |
| 34 | + this.firstBuildCompleted = false; |
| 35 | + } |
| 36 | + |
| 37 | + onOutput(message) { |
| 38 | + this.debug(message); |
| 39 | + |
| 40 | + if (message.toLowerCase().indexOf('error') > -1) { |
| 41 | + this.executeCommand.stop(); |
| 42 | + this.fail(); |
| 43 | + } else if (message.indexOf('webpack is watching the files') > -1) { |
| 44 | + this.success(); |
| 45 | + this.executeCommand.stop(); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + execute(context) { |
| 50 | + this.context = context; |
| 51 | + |
| 52 | + this.executeCommand = new ExecuteCommand('au', ['build', '--watch'], (msg) => this.onOutput(msg)); |
| 53 | + return this.executeCommand.executeAsNodeScript(); |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +function isBuildCompletedMessage(msg) { |
| 58 | + return msg.indexOf('Built at') > -1; |
| 59 | +} |
| 60 | + |
| 61 | +module.exports = { |
| 62 | + AuBuildDoesNotThrowCommandLineErrors, |
| 63 | + AuBuildStartsWebpackInWatchMode |
| 64 | +}; |
0 commit comments