Skip to content

Commit

Permalink
Merge pull request #4 from mauriziovitale/feature-improve-e2e-schematics
Browse files Browse the repository at this point in the history
Add e2e for schematics
  • Loading branch information
mauriziovitale authored Apr 12, 2020
2 parents 43b53d7 + b834a64 commit 96c7f17
Show file tree
Hide file tree
Showing 9 changed files with 13,230 additions and 6,524 deletions.
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'env': {
'browser': true,
'es6': true,
},
'extends': [
'google',
],
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly',
},
'parserOptions': {
'ecmaVersion': 2018,
'sourceType': 'module',
},
'rules': {
},
};
44 changes: 44 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
language: node_js
dist: trusty
sudo: required
node_js:
- "12.13.1"
git:
depth: 25
quiet: true

before_install:
- npm install -g yarn

install: npm install


branches:
only:
- master
- development

stages:
- name: "Test & Build"

jobs:
include:
- stage: "Test & Build"
name: Build
script: nx run lite-serve:build
- stage: "Test & Build"
name: Test
script:
- nx run lite-serve:build
- npm install file:dist/libs/lite-serve
- nx run lite-serve-e2e:e2e
- stage: deploy
if: branch == master and type == push && !fork
node_js: 'node' # pre-installed version
script:
- npm install -g semantic-release@^15
- nx run lite-serve:build
- npm run semantic-release

cache:
directories:
8 changes: 7 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"recommendations": [
"ms-vscode.vscode-typescript-tslint-plugin",
"esbenp.prettier-vscode"
"angular.ng-template",
"streetsidesoftware.code-spell-checker",
"ms-azuretools.vscode-docker",
"editorconfig.editorconfig",
"davidanson.vscode-markdownlint",
"esbenp.prettier-vscode",
"eamodio.gitlens"
]
}
77 changes: 77 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "jest",
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
"args": [
"--runInBand",
"--coverage=false",
"--config=`${workspaceFolder}/.vscode/closest-config-finder.sh ${file} jest.config.js`",
"${file}"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "jest watch",
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
"args": [
"--runInBand",
"--coverage=false",
"--watch",
"--config=`${workspaceFolder}/.vscode/closest-config-finder.sh ${file} jest.config.js`",
"${file}"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "e2e",
"program": "${workspaceFolder}/node_modules/protractor/bin/protractor",
"args": [
"`${workspaceFolder}/.vscode/closest-config-finder.sh ${file} protractor.conf.js`",
"--specs=${file}"
],
"envFile": "${workspaceFolder}/.env",
"console": "integratedTerminal",
"sourceMaps": true,
"smartStep": true,
"skipFiles": [
"${workspaceFolder}/node_modules/**/*.js",
"<node_internals>/**/*.js"
],
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "e2e with local adf",
"program": "${workspaceFolder}/node_modules/protractor/bin/protractor",
"args": [
"`${workspaceFolder}/.vscode/closest-config-finder.sh ${file} protractor.conf.js`",
"--specs=${file}",
"--disableChecks",
"--with-local-adf"
],
"envFile": "${workspaceFolder}/.env",
"console": "integratedTerminal",
"sourceMaps": true,
"smartStep": true,
"skipFiles": [
"${workspaceFolder}/node_modules/**/*.js",
"<node_internals>/**/*.js"
],
"internalConsoleOptions": "neverOpen"
}
]
}
26 changes: 26 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/.DS_Store": true,
"**/coverage": true,
"**/.happypack": true
},
"editor.renderIndentGuides": true,
"tslint.configFile": "tslint.json",
"markdownlint.config": {
"MD032": false,
"MD004": false,
"MD024": false,
"MD009": false,
"MD013": false,
"MD036": false,
"MD033" : false,
"MD031" : false
},
"cSpell.words": [
"webscript"
]
}
91 changes: 87 additions & 4 deletions apps/lite-serve-e2e/tests/lite-serve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,102 @@ import {
runNxCommandAsync,
uniq
} from '@nrwl/nx-plugin/testing';
import { readFileSync, writeFileSync } from 'fs';

describe('lite-serve e2e', () => {
it('should create lite-serve', async done => {
it('should setup an existing project', async done => {
const plugin = uniq('lite-serve');
ensureNxProject('@angular-custom-builders/lite-serve:setup', 'dist/libs/lite-serve');
const pluginE2EName = `${plugin}-e2e`;
const projects = { [plugin] : createAppDefinition(plugin), [pluginE2EName]: createAppE2EDefinition(pluginE2EName)};

patchWorkspaceJsonForPlugin(projects);

await runNxCommandAsync(
`g @angular-custom-builders/lite-serve:setup --name ${plugin}`
);
const result = await runNxCommandAsync(`run ${plugin}:lite-serve --port=432`);
expect(result.stdout).toContain(`lite-serve serving folder dist/apps/${plugin} on port 432`);

done();
});

it('should raise an exception in case the e2e project does not follow the default naming convention', async done => {
const plugin = uniq('lite-serve');
ensureNxProject('@angular-custom-builders/lite-serve:setup', 'dist/libs/lite-serve');

const pluginE2EName = `${plugin}-custom-e2e`;
const projects = { [plugin] : createAppDefinition(plugin), [pluginE2EName]: createAppE2EDefinition(pluginE2EName)};

patchWorkspaceJsonForPlugin(projects);

const result = await runNxCommandAsync(
`g @angular-custom-builders/lite-serve:setup --name ${plugin}`
);
expect(result.stderr).toContain(`The project ${plugin}-e2e does not exist`);

done();
});

it('should be able to setup a project with a custom e2e name', async done => {
const plugin = uniq('lite-serve');
ensureNxProject('@angular-custom-builders/lite-serve:setup', 'dist/libs/lite-serve');

const pluginE2EName = `${plugin}-custom-e2e`;
const projects = { [plugin] : createAppDefinition(plugin), [pluginE2EName]: createAppE2EDefinition(pluginE2EName)};

patchWorkspaceJsonForPlugin(projects);

await runNxCommandAsync(
`generate @angular-custom-builders/lite-serve:setup ${plugin}`
`g @angular-custom-builders/lite-serve:setup --name ${plugin} -e ${pluginE2EName}`
);
// const result = await runNxCommandAsync(`run ${plugin}:lite-server --port=432`);
// expect(result.stdout).toContain(`lite-serve serving folder dist on port 432`);
const result = await runNxCommandAsync(`run ${plugin}:lite-serve --port=432`);
expect(result.stdout).toContain(`lite-serve serving folder dist/apps/${plugin} on port 432`);

done();
});

function patchWorkspaceJsonForPlugin(projects) {
const p = JSON.parse(readFileSync(tmpProjPath('workspace.json')).toString());
p.projects = projects;
writeFileSync(tmpProjPath('workspace.json'), JSON.stringify(p, null, 2));
}

function createAppDefinition(plugin: string) {
return {
root: plugin,
sourceRoot: `${plugin}/src`,
projectType: 'application',
architect: {
build: {
builder: '@angular-devkit/build-angular:browser',
options: {
outputPath: `dist/apps/${plugin}`
}
}
}
}
}

function createAppE2EDefinition(plugin: string) {
return {
root: plugin,
sourceRoot: `${plugin}-e2e/src`,
projectType: 'application',
architect: {
e2e: {
options: {
devServerTarget: `${plugin}:serve`
}
}
}
}
}

function tmpProjPath(path?: string) {
return path
? `${process.cwd()}/tmp/nx-e2e/proj/${path}`
: `${process.cwd()}/tmp/nx-e2e/proj`;
}

});
3 changes: 2 additions & 1 deletion libs/lite-serve/src/schematics/lite-serve/schematic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LiteServeSchematicSchema } from './schema';

describe('lite-serve schematic', () => {
let appTree: Tree;

const options: LiteServeSchematicSchema = { name: 'test' };

const testRunner = new SchematicTestRunner(
Expand All @@ -20,7 +21,7 @@ describe('lite-serve schematic', () => {

it('should run successfully', async () => {
await expect(
testRunner.runSchematicAsync('liteServe', options, appTree).toPromise()
testRunner.runSchematicAsync('setup', options, appTree).toPromise()
).resolves.not.toThrowError();
});
});
Loading

0 comments on commit 96c7f17

Please sign in to comment.