Skip to content

Commit 770682a

Browse files
committed
chore(ngx-material-faq): added additional configuration setup
1 parent ef8b29d commit 770682a

File tree

6 files changed

+264
-0
lines changed

6 files changed

+264
-0
lines changed

config/helpers.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const os = require('os');
2+
const path = require('path');
3+
const exec = require('child_process').exec;
4+
5+
const _root = path.resolve(__dirname, '..');
6+
7+
8+
/**
9+
* Plaform independant path to an executable cmd
10+
* @param {string} path
11+
*/
12+
platformPath = (path) => {
13+
return /^win/.test(os.platform()) ? `${path}.cmd` : path;
14+
};
15+
16+
/**
17+
*
18+
* @param {string[]} args
19+
*/
20+
rootDir = (...args) => {
21+
return path.join.apply(path, [_root].concat(...args));
22+
};
23+
24+
/**
25+
*
26+
* @param {string} cmd
27+
*/
28+
binPath = (cmd) => {
29+
return platformPath(`/node_modules/.bin/${cmd}`);
30+
};
31+
32+
/**
33+
* Promisified child_process.exec
34+
*
35+
* @param cmd
36+
* @param opts See child_process.exec node docs
37+
* @returns {Promise<number>}
38+
*/
39+
execp = (cmd, opts) => {
40+
opts = Object.assign(opts || {}, {
41+
stdout: process.stdout,
42+
stderr: process.stderr
43+
});
44+
return new Promise((resolve, reject) => {
45+
const child = exec(cmd, opts,
46+
(err, stdout, stderr) => err ? reject(err.code) : resolve(0));
47+
48+
if (opts.stdout) {
49+
child.stdout.pipe(opts.stdout);
50+
}
51+
if (opts.stderr) {
52+
child.stderr.pipe(opts.stderr);
53+
}
54+
});
55+
};
56+
57+
/**
58+
* Install dependencies using yarn, if present, or npm otherwise.
59+
* @param opts See child_process.exec node docs
60+
* @returns {Promise<number>}
61+
*/
62+
installDependencies = (opts) => {
63+
return execp('yarn -v') // first try to install deps using yarn
64+
.then(exitCode => exitCode === 0 ? execp('yarn install', opts) : execp('npm install', opts));
65+
};
66+
67+
var exports = module.exports = {
68+
root: rootDir,
69+
execp: execp,
70+
binPath: binPath,
71+
platformPath: platformPath,
72+
installDependencies: installDependencies
73+
};

config/jestGlobalMocks.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
global['CSS'] = null;
2+
3+
const mock = () => {
4+
let storage = {};
5+
return {
6+
getItem: key => key in storage ? storage[key] : null,
7+
setItem: (key, value) => storage[key] = value || '',
8+
removeItem: key => delete storage[key],
9+
clear: () => storage = {},
10+
};
11+
};
12+
13+
Object.defineProperty(window, 'localStorage', {value: mock()});
14+
Object.defineProperty(window, 'sessionStorage', {value: mock()});
15+
Object.defineProperty(document, 'doctype', {
16+
value: '<!DOCTYPE html>'
17+
});
18+
Object.defineProperty(window, 'getComputedStyle', {
19+
value: () => {
20+
return {
21+
display: 'none',
22+
appearance: ['-webkit-appearance']
23+
};
24+
}
25+
});
26+
/**
27+
* ISSUE: https://github.com/angular/material2/issues/7101
28+
* Workaround for JSDOM missing transform property
29+
*/
30+
Object.defineProperty(document.body.style, 'transform', {
31+
value: () => {
32+
return {
33+
enumerable: true,
34+
configurable: true,
35+
};
36+
},
37+
});

config/setupJest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import 'jest-preset-angular';
2+
import './jestGlobalMocks';

tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "es2015",
5+
"moduleResolution": "node",
6+
"sourceMap": true,
7+
"inlineSources": true,
8+
"declaration": true,
9+
"experimentalDecorators": true,
10+
"noImplicitAny": true,
11+
"suppressImplicitAnyIndexErrors": true,
12+
"skipLibCheck": true,
13+
"stripInternal": true,
14+
"lib": [
15+
"es2015",
16+
"dom"
17+
]
18+
}
19+
}

tslint.json

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
{
2+
"rulesDirectory": [
3+
"node_modules/codelyzer"
4+
],
5+
"rules": {
6+
"arrow-return-shorthand": true,
7+
"callable-types": true,
8+
"class-name": true,
9+
"comment-format": [
10+
true,
11+
"check-space"
12+
],
13+
"curly": true,
14+
"eofline": true,
15+
"forin": true,
16+
"import-blacklist": [
17+
true,
18+
"rxjs"
19+
],
20+
"import-spacing": true,
21+
"indent": [
22+
true,
23+
"spaces"
24+
],
25+
"interface-over-type-literal": true,
26+
"label-position": true,
27+
"max-line-length": [
28+
true,
29+
140
30+
],
31+
"member-access": false,
32+
"member-ordering": [
33+
true,
34+
"static-before-instance",
35+
"variables-before-functions"
36+
],
37+
"no-arg": true,
38+
"no-bitwise": true,
39+
"no-console": [
40+
true,
41+
"debug",
42+
"info",
43+
"time",
44+
"timeEnd",
45+
"trace"
46+
],
47+
"no-construct": true,
48+
"no-debugger": true,
49+
"no-duplicate-super": true,
50+
"no-empty": false,
51+
"no-empty-interface": true,
52+
"no-eval": true,
53+
"no-inferrable-types": [
54+
true,
55+
"ignore-params"
56+
],
57+
"no-misused-new": true,
58+
"no-non-null-assertion": true,
59+
"no-shadowed-variable": true,
60+
"no-string-literal": false,
61+
"no-string-throw": true,
62+
"no-switch-case-fall-through": true,
63+
"no-trailing-whitespace": true,
64+
"no-unnecessary-initializer": true,
65+
"no-unused-expression": true,
66+
"no-use-before-declare": true,
67+
"no-var-keyword": true,
68+
"object-literal-sort-keys": false,
69+
"one-line": [
70+
true,
71+
"check-open-brace",
72+
"check-catch",
73+
"check-else",
74+
"check-whitespace"
75+
],
76+
"prefer-const": true,
77+
"quotemark": [
78+
true,
79+
"single"
80+
],
81+
"radix": true,
82+
"semicolon": [
83+
"always"
84+
],
85+
"triple-equals": [
86+
true,
87+
"allow-null-check"
88+
],
89+
"typedef-whitespace": [
90+
true,
91+
{
92+
"call-signature": "nospace",
93+
"index-signature": "nospace",
94+
"parameter": "nospace",
95+
"property-declaration": "nospace",
96+
"variable-declaration": "nospace"
97+
}
98+
],
99+
"typeof-compare": true,
100+
"unified-signatures": true,
101+
"variable-name": false,
102+
"whitespace": [
103+
true,
104+
"check-branch",
105+
"check-decl",
106+
"check-operator",
107+
"check-separator",
108+
"check-type"
109+
],
110+
"directive-selector": [
111+
true,
112+
"attribute",
113+
"ngx-material",
114+
"camelCase"
115+
],
116+
"component-selector": [
117+
true,
118+
"element",
119+
"ngx-material",
120+
"kebab-case"
121+
],
122+
"use-input-property-decorator": true,
123+
"use-output-property-decorator": true,
124+
"use-host-property-decorator": true,
125+
"no-input-rename": true,
126+
"no-output-rename": true,
127+
"use-life-cycle-interface": true,
128+
"use-pipe-transform-interface": true,
129+
"component-class-suffix": true,
130+
"directive-class-suffix": true
131+
}
132+
}

webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./config/webpack.test.js');

0 commit comments

Comments
 (0)