Skip to content

Commit

Permalink
feat(requirejs/systemjs): add protractor and jest support
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenVinke committed Jul 19, 2018
1 parent 10d6ff2 commit 4648877
Show file tree
Hide file tree
Showing 32 changed files with 118 additions and 243 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

module.exports = function(project) {
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function(project) {
require('../../general/integration-test-runner/protractor')(project);
};
5 changes: 5 additions & 0 deletions lib/commands/new/buildsystems/cli/unit-test-runners/jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function(project) {
require('../../general/unit-test-runners/jest')(project);
};
12 changes: 7 additions & 5 deletions lib/commands/new/buildsystems/cli/unit-test-runners/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ module.exports = function(project) {
).addToContent(
ProjectItem.resource('karma.conf.js', 'content/karma.conf.ext', project.model.transpiler),
project.tests.add(
project.unitTests.add(
ProjectItem.resource('setup.ext', 'test/setup.js', project.model.transpiler),
ProjectItem.resource('app.spec.ext', 'test/app.spec.js', project.model.transpiler)
),
ProjectItem.resource('setup.ext', 'test/setup.js', project.model.transpiler),
ProjectItem.resource('aurelia-karma.js', `test/${project.model.loader.id}.aurelia-karma.js`)
)
).addToDevDependencies(
Expand All @@ -30,6 +27,11 @@ module.exports = function(project) {
if (project.model.transpiler.id === 'babel') {
project.addToDevDependencies('karma-babel-preprocessor');
} else {
project.addToDevDependencies('karma-typescript-preprocessor', '@types/jasmine');
project.addToDevDependencies('karma-typescript-preprocessor');

// prevent duplicate typescript definitions
if (!project.model.unitTestRunners.find(x => x.id === 'jest')) {
project.addToDevDependencies('@types/jasmine');
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

module.exports = function(project) {
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';
const ProjectItem = require('../../../../../project-item').ProjectItem;

module.exports = function(project) {
let configPath;

if (project.model.transpiler.id === 'typescript') {
project.addToDevDependencies(
'ts-node'
);

// prevent duplicate typescript definitions
if (!project.model.unitTestRunners.find(x => x.id === 'jest')) {
project.addToDevDependencies('@types/jasmine');
}

configPath = 'test/protractor.typescript.conf.js';
} else if (project.model.transpiler.id === 'babel') {
configPath = 'test/protractor.babel.conf.js';
}

project.addToTasks(
ProjectItem.resource('protractor.ext', 'tasks/protractor.ext', project.model.transpiler),
ProjectItem.resource('protractor.json', 'tasks/protractor.json')
).addToDevDependencies(
'aurelia-protractor-plugin',
'protractor',
'gulp-protractor',
'wait-on'
).addToContent(
project.tests.add(
project.e2eTests.add(
ProjectItem.resource('demo.e2e.ext', 'test/e2e/demo.e2e.ext', project.model.transpiler),
ProjectItem.resource('skeleton.po.ext', 'test/e2e/skeleton.po.ext', project.model.transpiler),
ProjectItem.resource('welcome.po.ext', 'test/e2e/welcome.po.ext', project.model.transpiler)
),
ProjectItem.resource('protractor.conf.js', configPath)
)
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ module.exports = function(project) {
'displayName': 'Jasmine'
};

let transpilerId = project.model.transpiler.id;
let testContentRoot = `test/webpack/${transpilerId}`;

project.addToContent(
project.tests.add(
project.unitTests.add(
ProjectItem.resource('app.spec.ext', `${testContentRoot}/unit/app.spec.ext`, project.model.transpiler)
ProjectItem.resource('app.spec.ext', 'test/unit/app.spec.ext', project.model.transpiler)
)
)
);
Expand All @@ -22,7 +19,7 @@ module.exports = function(project) {
project.addToContent(
project.tests.add(
project.unitTests.add(
ProjectItem.resource('.eslintrc', `${testContentRoot}/unit/.eslintrc`)
ProjectItem.resource('.eslintrc', 'test/unit/.eslintrc')
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = function(project) {
).addToDevDependencies(
'jest',
'jest-cli',
'gulp-util',
'plugin-error',
'aurelia-loader-nodejs',
'aurelia-pal-nodejs'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
'use strict';
const ProjectItem = require('../../../../../project-item').ProjectItem;

module.exports = function(project) {
let transpilerId = project.model.transpiler.id;
let testContentRoot = `test/webpack/${transpilerId}`;

if (project.model.transpiler.id === 'babel') {
project.addToDevDependencies(
'ts-node'
);
}

project.addToDevDependencies(
'aurelia-protractor-plugin',
'protractor',
'wait-on'
).addToContent(
project.tests.add(
project.e2eTests.add(
ProjectItem.resource('demo.e2e.ext', `${testContentRoot}/e2e/demo.e2e.ext`, project.model.transpiler),
ProjectItem.resource('skeleton.po.ext', `${testContentRoot}/e2e/skeleton.po.ext`, project.model.transpiler),
ProjectItem.resource('welcome.po.ext', `${testContentRoot}/e2e/welcome.po.ext`, project.model.transpiler)
),
ProjectItem.resource('protractor.conf.js', `${testContentRoot}/protractor.conf.js`)
)
);

// prevent duplicate typescript definitions
if (!project.model.unitTestRunner.find(x => x.id === 'jest')) {
project.addToDevDependencies('@types/jasmine');
}
require('../../general/integration-test-runner/protractor')(project);
};
100 changes: 1 addition & 99 deletions lib/commands/new/buildsystems/webpack/unit-test-runners/jest.js
Original file line number Diff line number Diff line change
@@ -1,103 +1,5 @@
'use strict';
const ProjectItem = require('../../../../../project-item').ProjectItem;

module.exports = function(project) {
let configureJasmine = require('./jasmine');
configureJasmine(project);

let transpilerId = project.model.transpiler.id;
let testContentRoot = `test/webpack/${transpilerId}`;

project.addToTasks(
ProjectItem.resource('jest.ext', 'tasks/jest.ext', project.model.transpiler),
ProjectItem.resource('jest.json', 'tasks/jest.json')
).addToContent(
project.tests.add(
ProjectItem.resource('jest-pretest.ext', `${testContentRoot}/jest-pretest.ext`, project.model.transpiler)
)
).addToDevDependencies(
'jest',
'jest-cli',
'plugin-error',
'aurelia-loader-nodejs',
'aurelia-pal-nodejs'
);

if (project.model.transpiler.id === 'babel') {
project.addToDevDependencies(
'babel-jest'
);

project.package.jest = {
modulePaths: [
'<rootDir>/src',
'<rootDir>/node_modules'
],
moduleFileExtensions: [
'js',
'json'
],
transform: {
'^.+\\.jsx?$': 'babel-jest'
},
testRegex: '\\.spec\\.(ts|js)x?$',
setupFiles: [
'<rootDir>/test/jest-pretest.js'
],
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: [
'src/**/*.{js,ts}',
'!**/*.spec.{js,ts}',
'!**/node_modules/**',
'!**/test/**'
],
coverageDirectory: '<rootDir>/test/coverage-jest',
coverageReporters: [
'json',
'lcov',
'text',
'html'
]
};
} else if (project.model.transpiler.id === 'typescript') {
project.addToDevDependencies(
'ts-jest',
'@types/jest'
);

project.package.jest = {
modulePaths: [
'<rootDir>/src',
'<rootDir>/node_modules'
],
moduleFileExtensions: [
'js',
'json',
'ts'
],
transform: {
'^.+\\.(ts|tsx)$': '<rootDir>/node_modules/ts-jest/preprocessor.js'
},
testRegex: '\\.spec\\.(ts|js)x?$',
setupFiles: [
'<rootDir>/test/jest-pretest.ts'
],
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: [
'src/**/*.{js,ts}',
'!**/*.spec.{js,ts}',
'!**/node_modules/**',
'!**/test/**'
],
coverageDirectory: '<rootDir>/test/coverage-jest',
coverageReporters: [
'json',
'lcov',
'text',
'html'
]
};
}
require('../../general/unit-test-runners/jest')(project);
};
42 changes: 1 addition & 41 deletions lib/commands/new/new-application.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
{
"id": 650,
"type": "input-select",
"nextActivity": 660,
"nextActivity": 680,
"question": "What css processor would you like to use?",
"stateProperty": "cssProcessor",
"options": [
Expand Down Expand Up @@ -403,46 +403,6 @@
}
]
},
{
"type": "branch-switch",
"id": 660,
"stateProperty": "bundler",
"branches": [
{
"case": "cli",
"nextActivity": 670
},
{
"case": "webpack",
"nextActivity": 680
}
]
},
{
"id": 670,
"type": "input-select",
"nextActivity": 700,
"question": "Would you like to configure unit testing?",
"stateProperty": "unitTestRunner",
"options": [
{
"displayName": "Yes",
"description": "Configure your app with Jasmine and Karma.",
"value": {
"id": "karma",
"displayName": "Karma"
}
},
{
"displayName": "No",
"description": "Skip testing. My code is always perfect anyway.",
"value": {
"id": "none",
"displayName": "None"
}
}
]
},
{
"id": 680,
"type": "input-multiselect",
Expand Down
1 change: 1 addition & 0 deletions lib/dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"gulp-notify": "^3.2.0",
"gulp-plumber": "^1.2.0",
"gulp-postcss": "^7.0.1",
"gulp-protractor": "^4.1.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.1.0",
"gulp-sourcemaps": "^2.6.4",
Expand Down
16 changes: 16 additions & 0 deletions lib/resources/tasks/protractor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import gulp from 'gulp';
const {protractor, webdriver_update } = require('gulp-protractor');

gulp.task('webdriver_update', webdriver_update);

gulp.task('protractor', (cb) => {
gulp.src(['test/e2e/**/*.e2e.js'], { read: false }).pipe(protractor({
configFile: 'test/protractor.conf.js'
})).on('end', cb);
});

// Setting up the test task
export default gulp.series(
'webdriver_update',
'protractor'
);
4 changes: 4 additions & 0 deletions lib/resources/tasks/protractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "protractor",
"description": "Runs Protractor and reports the results. Start the application before running this task."
}
16 changes: 16 additions & 0 deletions lib/resources/tasks/protractor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as gulp from 'gulp';
const {protractor, webdriver_update } = require('gulp-protractor');

gulp.task('webdriver_update', webdriver_update);

gulp.task('protractor', (cb) => {
gulp.src(['test/e2e/**/*.e2e.ts'], { read: false }).pipe(protractor({
configFile: 'test/protractor.conf.js'
})).on('end', cb);
});

// Setting up the test task
export default gulp.series(
'webdriver_update',
'protractor'
);
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('aurelia skeleton app', function() {
});

it('should load the page and display the initial page title', async () => {
await expect(await poSkeleton.getCurrentPageTitle()).toBe('Aurelia Navigation Skeleton');
await expect(await poSkeleton.getCurrentPageTitle()).toContain('Aurelia');
});

it('should display greeting', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('aurelia skeleton app', function() {
});

it('should load the page and display the initial page title', async () => {
await expect(await poSkeleton.getCurrentPageTitle()).toBe('Aurelia Navigation Skeleton');
await expect(await poSkeleton.getCurrentPageTitle()).toContain('Aurelia');
});

it('should display greeting', async () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 4648877

Please sign in to comment.