Skip to content

Commit

Permalink
style: automatic standards (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturovt authored and just-jeb committed Nov 17, 2019
1 parent 04b5c69 commit 5871f63
Show file tree
Hide file tree
Showing 126 changed files with 1,085 additions and 985 deletions.
3 changes: 3 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-angular"]
}
23 changes: 9 additions & 14 deletions jest-common.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
module.exports = {
globals: {
"ts-jest": {
diagnostics: false
}
globals: {
'ts-jest': {
diagnostics: false,
},
transform: {
"^.+\\.tsx?$": "ts-jest"
},
moduleFileExtensions: [
"ts",
"tsx",
"js",
"json"
],
testEnvironment: "./jest-custom-environment"
},
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
testEnvironment: './jest-custom-environment',
};
36 changes: 19 additions & 17 deletions jest-custom-environment.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
const NodeEnvironment = require('jest-environment-node');

class JestCustomEnvironment extends NodeEnvironment {
constructor(config) {
super(config);
this.jestErrorHasInstance = this.global.Error[Symbol.hasInstance];
}
constructor(config) {
super(config);
this.jestErrorHasInstance = this.global.Error[Symbol.hasInstance];
}

async setup() {
await super.setup();
// Workaround for this bug https://github.com/facebook/jest/issues/2549
this.jestErrorHasInstance = this.global.Error[Symbol.hasInstance];
Object.defineProperty(this.global.Error, Symbol.hasInstance, {
value: target => target instanceof Error || this.jestErrorHasInstance(target)
});
}
async setup() {
await super.setup();
// Workaround for this bug https://github.com/facebook/jest/issues/2549
this.jestErrorHasInstance = this.global.Error[Symbol.hasInstance];
Object.defineProperty(this.global.Error, Symbol.hasInstance, {
value: target => target instanceof Error || this.jestErrorHasInstance(target),
});
}

async tearDown() {
Object.defineProperty(this.global.Error, Symbol.hasInstance, {value: this.jestErrorHasInstance});
await super.tearDown();
}
async tearDown() {
Object.defineProperty(this.global.Error, Symbol.hasInstance, {
value: this.jestErrorHasInstance,
});
await super.tearDown();
}
}

module.exports = JestCustomEnvironment;
module.exports = JestCustomEnvironment;
5 changes: 4 additions & 1 deletion jest-e2e.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
module.exports = {...require('./jest-common.config'), testRegex: `${process.cwd()}/e2e/.+\\.spec\\.ts`,};
module.exports = {
...require('./jest-common.config'),
testRegex: `${process.cwd()}/e2e/.+\\.spec\\.ts`,
};
5 changes: 4 additions & 1 deletion jest-ut.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
module.exports = {...require('./jest-common.config'), testRegex: `${process.cwd()}/(?!(e2e|examples)/).+\\.spec\\.ts`,};
module.exports = {
...require('./jest-common.config'),
testRegex: `${process.cwd()}/(?!(e2e|examples)/).+\\.spec\\.ts`,
};
23 changes: 13 additions & 10 deletions merge-schemes.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import {writeFileSync} from 'fs';
import {merge} from 'lodash';
import { writeFileSync } from 'fs';
import { merge } from 'lodash';

interface CustomSchema {
originalSchemaPath: string;
schemaExtensionPaths: string[],
newSchemaPath: string;
originalSchemaPath: string;
schemaExtensionPaths: string[];
newSchemaPath: string;
}

const wd = process.cwd();
const schemesToMerge: CustomSchema[] = require(`${wd}/src/schemes`);

for(const customSchema of schemesToMerge){
const originalSchema = require(customSchema.originalSchemaPath);
const schemaExtensions = customSchema.schemaExtensionPaths.map((path: string) => require(path));
const newSchema = schemaExtensions.reduce((extendedSchema: any, currentExtension: any) => merge(extendedSchema, currentExtension), originalSchema);
writeFileSync(customSchema.newSchemaPath, JSON.stringify(newSchema, null, 2), 'utf-8');
for (const customSchema of schemesToMerge) {
const originalSchema = require(customSchema.originalSchemaPath);
const schemaExtensions = customSchema.schemaExtensionPaths.map((path: string) => require(path));
const newSchema = schemaExtensions.reduce(
(extendedSchema: any, currentExtension: any) => merge(extendedSchema, currentExtension),
originalSchema
);
writeFileSync(customSchema.newSchemaPath, JSON.stringify(newSchema, null, 2), 'utf-8');
}
30 changes: 29 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,54 @@
"postbuild": "yarn test && yarn run e2e",
"build": "tsc && ts-node merge-schemes.ts",
"test": "jest src",
"e2e": "jest e2e"
"e2e": "jest e2e",
"format": "prettier --write \"**/*.{js,ts,html}\""
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.803.0",
"@angular/compiler": "^8.2.2",
"@angular/compiler-cli": "^8.2.2",
"@commitlint/cli": "^8.2.0",
"@commitlint/config-angular": "^8.2.0",
"@types/jest": "^24.0.0",
"@types/lodash": "^4.14.118",
"@types/node": "~12.12.4",
"@types/webpack": "^4.4.26",
"@types/webpack-dev-server": "^3.1.5",
"@types/webpack-merge": "^4.1.3",
"cpy-cli": "^2.0.0",
"husky": "^3.0.9",
"jest": "^24.7.1",
"lerna": "^3.18.3",
"lint-staged": "^9.4.3",
"lodash": "^4.17.11",
"prettier": "^1.19.1",
"quicktype": "^15.0.174",
"rimraf": "^3.0.0",
"ts-jest": "^24.0.0",
"ts-node": "~8.5.0",
"typescript": "3.5"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.ts": [
"prettier --write",
"git add"
]
},
"prettier": {
"semi": true,
"endOfLine": "lf",
"tabWidth": 2,
"printWidth": 100,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "avoid",
"singleQuote": true
}
}
38 changes: 18 additions & 20 deletions packages/custom-webpack/e2e/custom-webpack-browser-schema.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@

import {customWebpackConfig, indexTransform} from "./custom-webpack-config-schema";

import { customWebpackConfig, indexTransform } from './custom-webpack-config-schema';

describe('custom webpack browser builder test', () => {
let customWebpackBrowserSchema: any;
let customWebpackBrowserSchema: any;

beforeEach(() => {
jest.resetModules()
customWebpackBrowserSchema = require('../dist/browser/schema.json');
});
beforeEach(() => {
jest.resetModules();
customWebpackBrowserSchema = require('../dist/browser/schema.json');
});

it('Should fit the schema of @angular-devkit/build-angular:browser', () => {
const originalBrowserSchema = require('@angular-devkit/build-angular/src/browser/schema.json');
customWebpackBrowserSchema.properties['customWebpackConfig'] = undefined;
customWebpackBrowserSchema.properties['indexTransform'] = undefined;
expect(originalBrowserSchema.properties).toEqual(customWebpackBrowserSchema.properties);
});
it('Should fit the schema of @angular-devkit/build-angular:browser', () => {
const originalBrowserSchema = require('@angular-devkit/build-angular/src/browser/schema.json');
customWebpackBrowserSchema.properties['customWebpackConfig'] = undefined;
customWebpackBrowserSchema.properties['indexTransform'] = undefined;
expect(originalBrowserSchema.properties).toEqual(customWebpackBrowserSchema.properties);
});

it('Should contain customWebpackConfig', () => {
expect(customWebpackBrowserSchema.properties.customWebpackConfig).toEqual(customWebpackConfig);
});
it('Should contain customWebpackConfig', () => {
expect(customWebpackBrowserSchema.properties.customWebpackConfig).toEqual(customWebpackConfig);
});

it('Should contain indexTransform', () => {
expect(customWebpackBrowserSchema.properties.indexTransform).toEqual(indexTransform);
});
it('Should contain indexTransform', () => {
expect(customWebpackBrowserSchema.properties.indexTransform).toEqual(indexTransform);
});
});
24 changes: 15 additions & 9 deletions packages/custom-webpack/e2e/custom-webpack-config-schema.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
export const customWebpackConfig = {
"type": "object",
"description": "Custom webpack configuration",
"properties": {
"path": {"type": "string", "description": "Path to the custom webpack configuration file"},
"mergeStrategies": {"type": "object", "description": "Merge strategies per webpack config field"},
"replaceDuplicatePlugins": {"type": "boolean", "description": "Flag that indicates whether to replace duplicate webpack plugins or not"}
},
"default": false
type: 'object',
description: 'Custom webpack configuration',
properties: {
path: { type: 'string', description: 'Path to the custom webpack configuration file' },
mergeStrategies: { type: 'object', description: 'Merge strategies per webpack config field' },
replaceDuplicatePlugins: {
type: 'boolean',
description: 'Flag that indicates whether to replace duplicate webpack plugins or not',
},
},
default: false,
};

export const indexTransform = {"type": "string", "description": "Path to the file with index.html transform function" }
export const indexTransform = {
type: 'string',
description: 'Path to the file with index.html transform function',
};
37 changes: 18 additions & 19 deletions packages/custom-webpack/e2e/custom-webpack-karma-schema.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import {customWebpackConfig, indexTransform} from "./custom-webpack-config-schema";

import { customWebpackConfig, indexTransform } from './custom-webpack-config-schema';

describe('custom webpack karma builder test', () => {
let customWebpackBrowserSchema: any;
let customWebpackBrowserSchema: any;

beforeEach(() => {
jest.resetModules()
customWebpackBrowserSchema = require('../dist/karma/schema.json');
});
beforeEach(() => {
jest.resetModules();
customWebpackBrowserSchema = require('../dist/karma/schema.json');
});

it('Should fit the schema of @angular-devkit/build-angular:karma', () => {
const originalBrowserSchema = require('@angular-devkit/build-angular/src/karma/schema.json');
customWebpackBrowserSchema.properties['customWebpackConfig'] = undefined;
customWebpackBrowserSchema.properties['indexTransform'] = undefined;
expect(originalBrowserSchema.properties).toEqual(customWebpackBrowserSchema.properties);
});
it('Should fit the schema of @angular-devkit/build-angular:karma', () => {
const originalBrowserSchema = require('@angular-devkit/build-angular/src/karma/schema.json');
customWebpackBrowserSchema.properties['customWebpackConfig'] = undefined;
customWebpackBrowserSchema.properties['indexTransform'] = undefined;
expect(originalBrowserSchema.properties).toEqual(customWebpackBrowserSchema.properties);
});

it('Should contain customWebpackConfig', () => {
expect(customWebpackBrowserSchema.properties.customWebpackConfig).toEqual(customWebpackConfig);
});
it('Should contain customWebpackConfig', () => {
expect(customWebpackBrowserSchema.properties.customWebpackConfig).toEqual(customWebpackConfig);
});

it('Should contain indexTransform', () => {
expect(customWebpackBrowserSchema.properties.indexTransform).toEqual(indexTransform);
});
it('Should contain indexTransform', () => {
expect(customWebpackBrowserSchema.properties.indexTransform).toEqual(indexTransform);
});
});
36 changes: 18 additions & 18 deletions packages/custom-webpack/e2e/custom-webpack-server-schema.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import {customWebpackConfig, indexTransform} from "./custom-webpack-config-schema";
import { customWebpackConfig, indexTransform } from './custom-webpack-config-schema';

describe('custom webpack server builder test', () => {
let customWebpackBrowserSchema: any;
let customWebpackBrowserSchema: any;

beforeEach(() => {
jest.resetModules()
customWebpackBrowserSchema = require('../dist/server/schema.json');
});
beforeEach(() => {
jest.resetModules();
customWebpackBrowserSchema = require('../dist/server/schema.json');
});

it('Should fit the schema of @angular-devkit/build-angular:server', () => {
const originalBrowserSchema = require('@angular-devkit/build-angular/src/server/schema.json');
customWebpackBrowserSchema.properties['customWebpackConfig'] = undefined;
customWebpackBrowserSchema.properties['indexTransform'] = undefined;
expect(originalBrowserSchema.properties).toEqual(customWebpackBrowserSchema.properties);
});
it('Should fit the schema of @angular-devkit/build-angular:server', () => {
const originalBrowserSchema = require('@angular-devkit/build-angular/src/server/schema.json');
customWebpackBrowserSchema.properties['customWebpackConfig'] = undefined;
customWebpackBrowserSchema.properties['indexTransform'] = undefined;
expect(originalBrowserSchema.properties).toEqual(customWebpackBrowserSchema.properties);
});

it('Should contain customWebpackConfig', () => {
expect(customWebpackBrowserSchema.properties.customWebpackConfig).toEqual(customWebpackConfig);
});
it('Should contain customWebpackConfig', () => {
expect(customWebpackBrowserSchema.properties.customWebpackConfig).toEqual(customWebpackConfig);
});

it('Should contain indexTransform', () => {
expect(customWebpackBrowserSchema.properties.indexTransform).toEqual(indexTransform);
});
it('Should contain indexTransform', () => {
expect(customWebpackBrowserSchema.properties.indexTransform).toEqual(indexTransform);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const config = require('./protractor-ci.conf').config;

config.specs.push('./src/**/*.e2e-spec-prod.ts')
config.specs.push('./src/**/*.e2e-spec-prod.ts');

exports.config = config;
exports.config = config;
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const config = require('./protractor.conf').config;
config.capabilities = {
browserName: 'chrome',
chromeOptions: {
args: ['--headless', '--no-sandbox', '--disable-gpu']
}
args: ['--headless', '--no-sandbox', '--disable-gpu'],
},
};

exports.config = config;
exports.config = config;
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@
const { SpecReporter } = require('jasmine-spec-reporter');

/**
* @type { import("protractor").Config }
* @type {import('protractor').Config}
*/
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
specs: ['./src/**/*.e2e-spec.ts'],
capabilities: {
'browserName': 'chrome'
browserName: 'chrome',
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
print: function() {},
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json')
project: require('path').join(__dirname, './tsconfig.json'),
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
},
};
Loading

0 comments on commit 5871f63

Please sign in to comment.