Skip to content

Commit

Permalink
Merge pull request #1075 from huochunpeng/scaffold-plugin
Browse files Browse the repository at this point in the history
feat: scaffolding aurelia plugin project
  • Loading branch information
EisenbergEffect authored Mar 28, 2019
2 parents 5b0c13e + d6bab9d commit 50e6b4e
Show file tree
Hide file tree
Showing 72 changed files with 2,174 additions and 1,095 deletions.
4 changes: 3 additions & 1 deletion RELEASE_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ This is an automated testing tool for projects that were generated by the Aureli
1. open the terminal, go into an empty directory and run `au generate-skeletons`
2. from the CLI repository folder, run `gulp release-check --path C:/Development/Aurelia/TestApps --latest-cli-url aurelia/cli#master`, substituting the path with the correct one.
* Note, on Windows, run PowerShell with "run as administrator".
3. Select for which projects you would like to run the tests
3. Select for which projects you would like to run the tests.
* To test all projects automatically, add `--all` to previous command.
* To test subset projects automatically, add `--select requirejs,babel` (only tests projects using requirejs and babel) to previous command.
4. Wait until tests complete
5. in the CLI repository folder there is now a release-checks-results folder containing the output and other artifacts, such as screenshots. Check these screenshots to make sure that pages have rendered correctly

Expand Down
5 changes: 5 additions & 0 deletions build/tasks/release-checks/step.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const LogManager = require('aurelia-logging');
const _ = require('lodash');

module.exports = class Step {
constructor(title) {
Expand All @@ -13,4 +14,8 @@ module.exports = class Step {
getTitle() {
throw new Error('not implemented');
}

debug(message) {
this.logger.debug(_.trimEnd(message));
}
};
24 changes: 15 additions & 9 deletions build/tasks/release-checks/suite-steps.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
const path = require('path');
const tasks = require('./tasks/index');
const tests = require('./tests/index');
const applicable = require('../../../lib/workflow/applicable');

module.exports = function(suite) {
const features = suite.split('_');
const ext = applicable(features, 'typescript') ? '.ts' : '.js';
const plugin = applicable(features, 'plugin');

const steps = [
new tasks.ChangeDirectory(),
new tasks.InstallNodeModules(),
new tasks.InstallLatestAureliaCLI(),
new tests.generic.AuGenerateAttributeTests(ext),
new tests.generic.AuGenerateComponentTests(ext),
new tests.generic.AuGenerateElementTests(ext),
new tests.generic.AuGenerateValueConverterTests(ext),
new tests.generic.AuGenerateBindingBehaviorTests(ext),
new tests.generic.AuGenerateTaskTests(ext),
new tests.generic.AuGenerateGeneratorTests(ext)
new tests.generic.AuGenerateAttributeTests(ext, plugin),
new tests.generic.AuGenerateElementTests(ext, plugin),
new tests.generic.AuGenerateValueConverterTests(ext, plugin),
new tests.generic.AuGenerateBindingBehaviorTests(ext, plugin),
new tests.generic.AuGenerateTaskTests(ext, plugin),
new tests.generic.AuGenerateGeneratorTests(ext, plugin)
];

if (!plugin) {
steps.push(new tests.generic.AuGenerateComponentTests(ext));
} else {
steps.push(new tests.plugin.AuBuildPluginDoesNotThrowCommandLineErrors());
}

if (applicable(features, 'jest')) {
steps.push(
Expand Down Expand Up @@ -47,10 +53,10 @@ module.exports = function(suite) {
if (applicable(features, 'cli-bundler')) {
steps.push(
new tests.requirejs.AuBuildDoesNotThrowCommandLineErrors(),
new tests.requirejs.AuBuildWatchPicksUpFileChanges(),
new tests.requirejs.AuBuildWatchPicksUpFileChanges(plugin ? path.join('dev-app', 'app.html') : undefined),
new tests.requirejs.AuRunDoesNotThrowCommandLineErrors(),
new tests.requirejs.AuRunLaunchesServer(),
new tests.requirejs.AuRunWatchPicksUpFileChanges(),
new tests.requirejs.AuRunWatchPicksUpFileChanges(plugin ? path.join('dev-app', 'app.html') : undefined),
new tests.requirejs.AuRunAppLaunchesWithoutJavascriptErrors(),
new tests.requirejs.AuRunRendersPage(),
new tests.generic.AuLintFinishes()
Expand Down
11 changes: 9 additions & 2 deletions build/tasks/release-checks/test-projects-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const CLIOptions = require('../../../lib/cli-options').CLIOptions;
const cliOptions = new CLIOptions();
const fs = require('../../../lib/file-system');
const path = require('path');
const _ = require('lodash');

let userArgs = process.argv.slice(2);
Object.assign(cliOptions, {
Expand Down Expand Up @@ -37,7 +38,14 @@ module.exports = class TestProjectsSelector {
let dirs = await this.getSubDirs(dir);

if (dirs.length === 0) throw new Error('No subdirectory to test.');
if (!CLIOptions.hasFlag('all')) {

if (cliOptions.hasFlag('select')) {
const selectedFeatures = cliOptions.getFlagValue('select').split(',');
dirs = dirs.filter(d => {
const features = d.split('_');
return _.every(selectedFeatures, f => _.includes(features, f));
});
} else if (!cliOptions.hasFlag('all')) {
dirs = await this.choose(dirs);
}

Expand All @@ -49,7 +57,6 @@ module.exports = class TestProjectsSelector {
options.unshift({displayName: 'All'});

const answers = await ui.multiselect('Found test dirs.\r\nWhich would you like to run?', options);
console.log('answers', answers);
return answers.includes('All') ? dirs : answers;
}
};
8 changes: 4 additions & 4 deletions build/tasks/release-checks/tests/generic/au-cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AuCypressRunsTests extends Test {
}

onCypressOutput(message) {
this.logger.debug(message);
this.debug(message);

if (isCypressCompletedMessage(message)) {
this.success();
Expand All @@ -21,7 +21,7 @@ class AuCypressRunsTests extends Test {
}

onOutput(message) {
this.logger.debug(message);
this.debug(message);

if (isApplicationAvailableMessage(message)) {
this.cypressCommand = new ExecuteCommand('au', ['cypress', '--run'], (msg) => this.onCypressOutput(msg), (msg) => this.onCypressOutput(msg));
Expand All @@ -41,7 +41,7 @@ class AuCypressRunsTestsDotNet extends Test {
}

onCypressOutput(message) {
this.logger.debug(message);
this.debug(message);

if (isCypressCompletedMessage(message)) {
this.success();
Expand All @@ -55,7 +55,7 @@ class AuCypressRunsTestsDotNet extends Test {
}

onOutput(message) {
this.logger.debug(message);
this.debug(message);

if (message.indexOf('Now listening on: http://localhost:') > -1) {
this.cypressCommand = new ExecuteCommand('au', ['cypress'], (msg) => this.onCypressOutput(msg), (msg) => this.onCypressOutput(msg));
Expand Down
42 changes: 26 additions & 16 deletions build/tasks/release-checks/tests/generic/au-generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ const path = require('path');
const _ = require('lodash');

class AuGenerateTests extends Test {
constructor(objectType, ext) {
constructor(objectType, ext, plugin) {
super(`au generate ${objectType}, writes ${objectType} file`);
this.objectType = objectType;
this.plugin = plugin;
this.ext = ext;
this.onFinish = this.onFinish.bind(this);
}

onFinish(message) {
this.logger.debug(message);
this.debug(message);

if (_.every(this.createdFiles(), fs.isFile)) {
this.success();
Expand All @@ -28,13 +29,22 @@ class AuGenerateTests extends Test {
path.join('src', `new-thing${this.ext}`)
];
} else if (this.objectType === 'element') {
if (this.plugin) {
return [
path.join('src', 'elements', 'new-thing.html'),
path.join('src', 'elements', `new-thing${this.ext}`)
];
}
return [
path.join('src', 'resources', 'elements', 'new-thing.html'),
path.join('src', 'resources', 'elements', `new-thing${this.ext}`)
];
} else if (this.objectType === 'task' || this.objectType === 'generator') {
return [path.join('aurelia_project', this.objectType + 's', `new-thing${this.ext}`)];
}
if (this.plugin) {
return [path.join('src', this.objectType + 's', `new-thing${this.ext}`)];
}
return [path.join('src', 'resources', this.objectType + 's', `new-thing${this.ext}`)];
}

Expand All @@ -56,44 +66,44 @@ class AuGenerateTests extends Test {
}

class AuGenerateAttributeTests extends AuGenerateTests {
constructor(ext) {
super('attribute', ext);
constructor(ext, plugin) {
super('attribute', ext, plugin);
}
}

class AuGenerateComponentTests extends AuGenerateTests {
constructor(ext) {
super('component', ext);
constructor(ext, plugin) {
super('component', ext, plugin);
}
}

class AuGenerateElementTests extends AuGenerateTests {
constructor(ext) {
super('element', ext);
constructor(ext, plugin) {
super('element', ext, plugin);
}
}

class AuGenerateValueConverterTests extends AuGenerateTests {
constructor(ext) {
super('value-converter', ext);
constructor(ext, plugin) {
super('value-converter', ext, plugin);
}
}

class AuGenerateBindingBehaviorTests extends AuGenerateTests {
constructor(ext) {
super('binding-behavior', ext);
constructor(ext, plugin) {
super('binding-behavior', ext, plugin);
}
}

class AuGenerateTaskTests extends AuGenerateTests {
constructor(ext) {
super('task', ext);
constructor(ext, plugin) {
super('task', ext, plugin);
}
}

class AuGenerateGeneratorTests extends AuGenerateTests {
constructor(ext) {
super('generator', ext);
constructor(ext, plugin) {
super('generator', ext, plugin);
}
}

Expand Down
2 changes: 1 addition & 1 deletion build/tasks/release-checks/tests/generic/au-jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AuJestRunsTests extends Test {
}

onOutput(message) {
this.logger.debug(message);
this.debug(message);

if (isTestFinishedMessage(message)) {
this.success();
Expand Down
2 changes: 1 addition & 1 deletion build/tasks/release-checks/tests/generic/au-karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AuKarmaRunsTests extends Test {
}

onOutput(message) {
this.logger.debug(message);
this.debug(message);

if (isTestFinishedMessage(message)) {
this.success();
Expand Down
2 changes: 1 addition & 1 deletion build/tasks/release-checks/tests/generic/au-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AuLintFinishes extends Test {
}

onOutput(message) {
this.logger.debug(message);
this.debug(message);

if (isTestFinishedMessage(message)) {
this.success();
Expand Down
8 changes: 4 additions & 4 deletions build/tasks/release-checks/tests/generic/au-protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AuProtractorRunsTests extends Test {
}

onProtractorOutput(message) {
this.logger.debug(message);
this.debug(message);

if (isProtractorCompletedMessage(message)) {
this.success();
Expand All @@ -17,7 +17,7 @@ class AuProtractorRunsTests extends Test {
}

onOutput(message) {
this.logger.debug(message);
this.debug(message);

if (isApplicationAvailableMessage(message)) {
this.protractorCommand = new ExecuteCommand('au', ['protractor'], (msg) => this.onProtractorOutput(msg));
Expand All @@ -38,7 +38,7 @@ class AuProtractorRunsTestsDotNet extends Test {
}

onProtractorOutput(message) {
this.logger.debug(message);
this.debug(message);

if (isProtractorCompletedMessage(message)) {
this.success();
Expand All @@ -48,7 +48,7 @@ class AuProtractorRunsTestsDotNet extends Test {
}

onOutput(message) {
this.logger.debug(message);
this.debug(message);

if (message.indexOf('Now listening on: http://localhost:') > -1) {
this.protractorCommand = new ExecuteCommand('au', ['protractor'], (msg) => this.onProtractorOutput(msg));
Expand Down
8 changes: 4 additions & 4 deletions build/tasks/release-checks/tests/generic/dotnet-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DotNetRunDoesNotThrowCommandLineErrors extends Test {
}

onOutput(message) {
this.logger.debug(message);
this.debug(message);

if (message.toLowerCase().indexOf('error') > -1) {
this.executeCommand.stop();
Expand All @@ -34,7 +34,7 @@ class DotNetRunLaunchesServer extends Test {
}

onOutput(message) {
this.logger.debug(message);
this.debug(message);

if (isApplicationAvailableMessage(message)) {
this.success();
Expand All @@ -54,7 +54,7 @@ class DotnetRunRendersPage extends Test {
}

onOutput(context, message) {
this.logger.debug(message);
this.debug(message);

if (isApplicationAvailableMessage(message)) {
const url = getURL(message);
Expand All @@ -81,7 +81,7 @@ class DotNetRunAppLaunchesWithoutJavascriptErrors extends Test {
}

onOutput(message) {
this.logger.debug(message);
this.debug(message);

if (isApplicationAvailableMessage(message)) {
const url = getURL(message);
Expand Down
3 changes: 2 additions & 1 deletion build/tasks/release-checks/tests/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
generic: require('./generic'),
requirejs: require('./requirejs'),
webpack: require('./webpack')
webpack: require('./webpack'),
plugin: require('./plugin')
};
33 changes: 33 additions & 0 deletions build/tasks/release-checks/tests/plugin/au-build-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const Test = require('../test');
const ExecuteCommand = require('../../tasks/execute-command');

class AuBuildPluginDoesNotThrowCommandLineErrors extends Test {
constructor() {
super('au build-plugin does not throw commandline errors');
}

onOutput(message) {
this.debug(message);

if (message.toLowerCase().indexOf('error') > -1) {
this.executeCommand.stop();
this.fail();
} else if (isBuildCompletedMessage(message)) {
this.success();
this.executeCommand.stop();
}
}

execute() {
this.executeCommand = new ExecuteCommand('au', ['build-plugin', '--watch'], (msg) => this.onOutput(msg));
return this.executeCommand.executeAsNodeScript();
}
}

function isBuildCompletedMessage(msg) {
return msg.indexOf('Finish building Aurelia plugin') > -1;
}

module.exports = {
AuBuildPluginDoesNotThrowCommandLineErrors
};
3 changes: 3 additions & 0 deletions build/tasks/release-checks/tests/plugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('./au-build-plugin')
};
Loading

0 comments on commit 50e6b4e

Please sign in to comment.