@muonic/muon 0.0.2-experimental-154-bdd17ca.0 → 0.0.2-experimental-156-ab51545.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nycrc +17 -0
- package/CHANGELOG.md +43 -0
- package/package.json +4 -2
- package/scripts/utils/config.mjs +30 -0
- package/scripts/utils/index.mjs +5 -29
- package/tests/scripts/utils/card-component.js +26 -0
- package/tests/scripts/utils/muon.config.test.json +13 -0
- package/tests/scripts/utils/single.component.config.json +5 -0
- package/tests/scripts/utils/test-runner.mjs +1 -0
- package/tests/scripts/utils/utils-test.mjs +284 -0
- package/tests/scripts/utils/test.json +0 -9
- package/tests/scripts/utils/utils-test.js +0 -134
package/.nycrc
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"report-dir": "./coverage/scripts-coverage",
|
|
3
|
+
"reporter": [
|
|
4
|
+
"html",
|
|
5
|
+
"text"
|
|
6
|
+
],
|
|
7
|
+
"exclude": [
|
|
8
|
+
"**/modular-scale.js",
|
|
9
|
+
"tests",
|
|
10
|
+
"tokens/**/string.js"
|
|
11
|
+
],
|
|
12
|
+
"check-coverage": true,
|
|
13
|
+
"lines": 99,
|
|
14
|
+
"branches": 99,
|
|
15
|
+
"functions":99,
|
|
16
|
+
"statements": 99
|
|
17
|
+
}
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.0.2-beta.0](https://github.com/centrica-engineering/muon/compare/v0.0.2-alpha.2...v0.0.2-beta.0) (2022-10-04)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* form comp ([8dd5fb6](https://github.com/centrica-engineering/muon/commit/8dd5fb66caeb0c3ed53a18497b6d4d00006d73a8))
|
|
11
|
+
* layout-row tokens and styles ([e221d8a](https://github.com/centrica-engineering/muon/commit/e221d8a7677be49a24f7e3974b46c672d863171e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* analyzer ([018a59a](https://github.com/centrica-engineering/muon/commit/018a59a9f8e92b72f18a8d1f605dc8500aefeba0))
|
|
17
|
+
* analyzer rollup ([ef8c7aa](https://github.com/centrica-engineering/muon/commit/ef8c7aaef0fe15cc0bbbb78945f0137ba89ee321))
|
|
18
|
+
* analyzer to include components from node_modules ([32bace4](https://github.com/centrica-engineering/muon/commit/32bace4403dc007b84bb49bc59aa580351558c78))
|
|
19
|
+
* automation failures ([238d9bf](https://github.com/centrica-engineering/muon/commit/238d9bf0c70576ef9a24ab8984fc7176656c2c23))
|
|
20
|
+
* ava version ([1851f5e](https://github.com/centrica-engineering/muon/commit/1851f5e10c9a119a81e17e9afffdd14436f028ae))
|
|
21
|
+
* browserstack test failure ([a471e5c](https://github.com/centrica-engineering/muon/commit/a471e5c7995a5564d034460b0dcca39aa344db07))
|
|
22
|
+
* build error ([25b6a9d](https://github.com/centrica-engineering/muon/commit/25b6a9d166b5ab9f4e8aa5d67ab13f9fcd7d2551))
|
|
23
|
+
* clean rollup output path ([7d37480](https://github.com/centrica-engineering/muon/commit/7d37480bbc770b790a47ea246956a25a83bffa7b))
|
|
24
|
+
* cleanup dist before rollup ([24cb36a](https://github.com/centrica-engineering/muon/commit/24cb36a6a9a5fb6c823ceaa5e05a9cf3f0024f64))
|
|
25
|
+
* cleanup muon files for every build & serve ([e8b76c3](https://github.com/centrica-engineering/muon/commit/e8b76c3d2d372dd54e00969d4598e7b7694f61a6))
|
|
26
|
+
* cleanup util ([67b0e34](https://github.com/centrica-engineering/muon/commit/67b0e349fe9c06bc0310f9b0e7810a08477a9de5))
|
|
27
|
+
* command injection ([8f529aa](https://github.com/centrica-engineering/muon/commit/8f529aa095b8ec1d64c8abf2ea5b3d42ba3813d8))
|
|
28
|
+
* deplicate tag check ([7acd409](https://github.com/centrica-engineering/muon/commit/7acd4090a4e1ed3c352e3e3605c6308ea6f52f13))
|
|
29
|
+
* **deps:** fixing build and tests ([388eea8](https://github.com/centrica-engineering/muon/commit/388eea8956d24bfedf1d54959ed912ec22ba61c7))
|
|
30
|
+
* **deps:** packages ([a42388e](https://github.com/centrica-engineering/muon/commit/a42388e49a04c402d0aa8e5f34bab7c4109d1d51))
|
|
31
|
+
* **deps:** update dependencies ([19f8736](https://github.com/centrica-engineering/muon/commit/19f8736f06fb1e48e7af41a6a40c02e1f19885ff))
|
|
32
|
+
* **deps:** update vulnerabilities ([c0aad11](https://github.com/centrica-engineering/muon/commit/c0aad11e69d18a12cedf04927ed29247d3972648))
|
|
33
|
+
* eslint warning ([789b296](https://github.com/centrica-engineering/muon/commit/789b2961c56365a7c01e2ea3b0d3141fb2aa41dc))
|
|
34
|
+
* examples story path ([aa53050](https://github.com/centrica-engineering/muon/commit/aa530500a34b0c9fe50a0afa4c17926967033b7d))
|
|
35
|
+
* lint errors ([5938f65](https://github.com/centrica-engineering/muon/commit/5938f6566c71217553f557428d107bc0eb8a59ab))
|
|
36
|
+
* missing resolve dep ([f026873](https://github.com/centrica-engineering/muon/commit/f02687382dbf03d7f40f5a89835a5c488b9cd410))
|
|
37
|
+
* remove redundent code ([a414686](https://github.com/centrica-engineering/muon/commit/a414686ccb33016c1c2101ce20df33252fab69b7))
|
|
38
|
+
* remove staticHTML from template ([23196a3](https://github.com/centrica-engineering/muon/commit/23196a32b42652a726a0c82e7884e78f9790ab58))
|
|
39
|
+
* remove test ([41e7bbb](https://github.com/centrica-engineering/muon/commit/41e7bbb5e3127ca8a00c97a110986677be787a71))
|
|
40
|
+
* reset test fixtures ([1bf64f4](https://github.com/centrica-engineering/muon/commit/1bf64f4bc15c36396027a402d14eefbc277a0ff8))
|
|
41
|
+
* reset value ([b8682ee](https://github.com/centrica-engineering/muon/commit/b8682ee9b3deb7022cd49040f1264f417223c30f))
|
|
42
|
+
* reset web component values ([40da965](https://github.com/centrica-engineering/muon/commit/40da9653e76474d973e766951c5ddf9c6249df6e))
|
|
43
|
+
* test failure ([694fc36](https://github.com/centrica-engineering/muon/commit/694fc360c4db676b649aa64eb508fe30adf51b46))
|
|
44
|
+
* test failure ([16d0075](https://github.com/centrica-engineering/muon/commit/16d00750d5383755025e41e49adba5cc01b834cf))
|
|
45
|
+
* test failures ([c6fd411](https://github.com/centrica-engineering/muon/commit/c6fd41117c5201218721bc0c2501a5e4fca3fb93))
|
|
46
|
+
* tmp directory skip ([58e9333](https://github.com/centrica-engineering/muon/commit/58e9333db57dac6400e2e612232125d8dcf56331))
|
|
47
|
+
|
|
5
48
|
### [0.0.2-alpha.2](https://github.com/centrica-engineering/muon/compare/v0.0.2-alpha.1...v0.0.2-alpha.2) (2022-04-07)
|
|
6
49
|
|
|
7
50
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muonic/muon",
|
|
3
|
-
"version": "0.0.2-experimental-
|
|
3
|
+
"version": "0.0.2-experimental-156-ab51545.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "web-test-runner \"./tests/**/*.test.js\" --coverage",
|
|
8
|
-
"test:scripts": "ava \"tests/scripts/utils/utils-test.
|
|
8
|
+
"test:scripts": "NODE_OPTIONS=--loader=esmock c8 ava \"tests/scripts/utils/utils-test.mjs\"",
|
|
9
9
|
"test:browserstack": "web-test-runner \"./tests/**/*.test.js\" --config web-test-runner.browserstack.config.mjs",
|
|
10
10
|
"release": "standard-version"
|
|
11
11
|
},
|
|
@@ -58,6 +58,8 @@
|
|
|
58
58
|
"@web/test-runner-browserstack": "0.5.1",
|
|
59
59
|
"@web/test-runner-playwright": "0.8.10",
|
|
60
60
|
"ava": "4.3.3",
|
|
61
|
+
"c8": "^7.12.0",
|
|
62
|
+
"esmock": "^2.0.3",
|
|
61
63
|
"sinon": "14.0.0"
|
|
62
64
|
},
|
|
63
65
|
"engines": {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import appRoot from 'app-root-path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
|
|
5
|
+
const getConfig = (configFile = 'muon.config.json') => {
|
|
6
|
+
let config = {};
|
|
7
|
+
try {
|
|
8
|
+
let configPath = path.join(process.cwd(), configFile);
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(configPath)) {
|
|
11
|
+
configPath = path.join(`${appRoot}/${configFile}`);
|
|
12
|
+
}
|
|
13
|
+
config = JSON.parse(fs.readFileSync(configPath).toString());
|
|
14
|
+
} catch (e) {
|
|
15
|
+
console.error('Missing config, is this the right folder?', e);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return config;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const getDestination = () => {
|
|
23
|
+
const config = getConfig();
|
|
24
|
+
return config?.destination || 'dist';
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
getConfig,
|
|
29
|
+
getDestination
|
|
30
|
+
};
|
package/scripts/utils/index.mjs
CHANGED
|
@@ -13,14 +13,12 @@ import styleConfig from '../style-dictionary.mjs';
|
|
|
13
13
|
import colorTransform from '../../tokens/utils/transforms/color.js';
|
|
14
14
|
import stringTransform from '../../tokens/utils/transforms/string.js';
|
|
15
15
|
import jsonReference from '../../tokens/utils/formats/reference.js';
|
|
16
|
-
|
|
16
|
+
import { getConfig, getDestination } from './config.mjs';
|
|
17
17
|
import { fileURLToPath } from 'url';
|
|
18
18
|
|
|
19
19
|
const __filename = fileURLToPath(import.meta.url);
|
|
20
20
|
const __dirname = path.dirname(__filename);
|
|
21
21
|
|
|
22
|
-
let config = {};
|
|
23
|
-
|
|
24
22
|
const cleanup = (destination, cleanOnRollup = false) => {
|
|
25
23
|
return new Promise((resolve) => {
|
|
26
24
|
const cemFilePath = path.join(destination, 'custom-elements.json');
|
|
@@ -29,10 +27,9 @@ const cleanup = (destination, cleanOnRollup = false) => {
|
|
|
29
27
|
if (fs.existsSync(destination)) {
|
|
30
28
|
if (cleanOnRollup) {
|
|
31
29
|
// eslint-disable-next-line no-unused-expressions
|
|
32
|
-
fs.
|
|
30
|
+
fs.rmSync(cemFilePath, { force: true });
|
|
33
31
|
} else {
|
|
34
32
|
fs.rmSync(destination, { force: true, recursive: true });
|
|
35
|
-
fs.rmSync(buildPath, { force: true, recursive: true });
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
|
|
@@ -40,28 +37,13 @@ const cleanup = (destination, cleanOnRollup = false) => {
|
|
|
40
37
|
fs.mkdirSync(destination);
|
|
41
38
|
}
|
|
42
39
|
if (!cleanOnRollup) {
|
|
40
|
+
fs.rmSync(buildPath, { force: true, recursive: true });
|
|
43
41
|
fs.mkdirSync(buildPath);
|
|
44
42
|
}
|
|
45
43
|
return resolve();
|
|
46
44
|
});
|
|
47
45
|
};
|
|
48
46
|
|
|
49
|
-
const getConfig = (configFile = 'muon.config.json') => {
|
|
50
|
-
try {
|
|
51
|
-
let configPath = path.join(process.cwd(), configFile);
|
|
52
|
-
|
|
53
|
-
if (!fs.existsSync(configPath)) {
|
|
54
|
-
configPath = path.join(`${appRoot}/${configFile}`);
|
|
55
|
-
}
|
|
56
|
-
config = JSON.parse(fs.readFileSync(configPath).toString());
|
|
57
|
-
} catch (e) {
|
|
58
|
-
console.error('Missing config, is this the right folder?', e);
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return config;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
47
|
const filterPathToCustomElements = async (componentsList) => {
|
|
66
48
|
let pathPattern = '*';
|
|
67
49
|
if (Array.isArray(componentsList) && componentsList?.length > 0) {
|
|
@@ -165,7 +147,7 @@ const getAliasPaths = (type) => {
|
|
|
165
147
|
find,
|
|
166
148
|
replacement: path.join(process.cwd(), replacement)
|
|
167
149
|
};
|
|
168
|
-
}).filter((alias) => alias)
|
|
150
|
+
}).filter((alias) => alias);
|
|
169
151
|
|
|
170
152
|
const defaultAlias = objGlobToRegexArr(defaultPaths);
|
|
171
153
|
|
|
@@ -197,8 +179,7 @@ const sourceFilesAnalyzer = async () => {
|
|
|
197
179
|
baseUrl: '.',
|
|
198
180
|
paths
|
|
199
181
|
};
|
|
200
|
-
const
|
|
201
|
-
const program = ts.createProgram(filePaths, options);
|
|
182
|
+
const program = ts.createProgram(files, options);
|
|
202
183
|
const sourceFiles = program.getSourceFiles().filter((sf) => files.includes(sf.fileName));
|
|
203
184
|
|
|
204
185
|
const results = sourceFiles.map((sourceFile) => analyzeSourceFile(sourceFile, {
|
|
@@ -281,11 +262,6 @@ const componentDefiner = async () => {
|
|
|
281
262
|
return componentDefinition;
|
|
282
263
|
};
|
|
283
264
|
|
|
284
|
-
const getDestination = () => {
|
|
285
|
-
const config = getConfig();
|
|
286
|
-
return config?.destination || 'dist';
|
|
287
|
-
};
|
|
288
|
-
|
|
289
265
|
const runner = async (file, overrideDestination) => {
|
|
290
266
|
const destination = overrideDestination || getDestination();
|
|
291
267
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Card } from '@muonic/muon/components/card';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A fancier version of the card.
|
|
5
|
+
*
|
|
6
|
+
* @element card
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export class FancyCard extends Card {
|
|
11
|
+
|
|
12
|
+
static get properties() {
|
|
13
|
+
return {
|
|
14
|
+
fancy: { type: Boolean }
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get coolBean() {
|
|
19
|
+
return 'cool beans';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
something() {
|
|
23
|
+
return 'doing something';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"components": {
|
|
3
|
+
"included": ["inputter" ,"card","image"],
|
|
4
|
+
"dir": "tests/scripts/utils/*-component.js"
|
|
5
|
+
},
|
|
6
|
+
"tokens": {
|
|
7
|
+
"dir": ["tokens/*.json"],
|
|
8
|
+
"theme": "default"
|
|
9
|
+
},
|
|
10
|
+
"alias": {
|
|
11
|
+
"@muon/utils/validation": "./utils/validation"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log('test runner function');
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import testRunner from 'ava';
|
|
2
|
+
import sinon from 'sinon';
|
|
3
|
+
import appRoot from 'app-root-path';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import esmock from 'esmock';
|
|
8
|
+
import * as utilsLibrary from '../../../scripts/utils/index.mjs';
|
|
9
|
+
|
|
10
|
+
testRunner('filterPathToCustomElements default', async (t) => {
|
|
11
|
+
const componentList = await utilsLibrary.filterPathToCustomElements('all');
|
|
12
|
+
t.is(componentList, '*');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
testRunner('filterPathToCustomElements default array', async (t) => {
|
|
16
|
+
const componentList = await utilsLibrary.filterPathToCustomElements(['all']);
|
|
17
|
+
t.is(componentList, '*');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
testRunner('filterPathToCustomElements single component', async (t) => {
|
|
21
|
+
const componentList = await utilsLibrary.filterPathToCustomElements('inputter');
|
|
22
|
+
t.is(componentList, 'inputter');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
testRunner('filterPathToCustomElements single component in array', async (t) => {
|
|
26
|
+
const componentList = await utilsLibrary.filterPathToCustomElements(['inputter']);
|
|
27
|
+
t.is(componentList, 'inputter');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
testRunner('filterPathToCustomElements multiple component', async (t) => {
|
|
31
|
+
const componentList = await utilsLibrary.filterPathToCustomElements(['inputter', 'image']);
|
|
32
|
+
t.is(componentList, '{inputter,image}');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
testRunner('getConfig default file and root', async (t) => {
|
|
36
|
+
const config = utilsLibrary.getConfig();
|
|
37
|
+
t.true(config !== undefined);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
testRunner('getConfig new file default root', async (t) => {
|
|
41
|
+
const config = utilsLibrary.getConfig('browserstack.json');
|
|
42
|
+
t.true(config !== undefined);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
testRunner('getConfig config file not exist', async (t) => {
|
|
46
|
+
const stub = sinon.stub(process, 'exit');
|
|
47
|
+
utilsLibrary.getConfig('test.json');
|
|
48
|
+
t.true(process.exit.called);
|
|
49
|
+
t.true(process.exit.calledWith(1));
|
|
50
|
+
stub.restore();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
testRunner('getConfig config file', async (t) => {
|
|
54
|
+
const config = utilsLibrary.getConfig('tests/scripts/utils/muon.config.test.json');
|
|
55
|
+
t.true(config !== undefined);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const componentsDefinitionMacro = async (t, expected) => {
|
|
59
|
+
const componentDefinition = await utilsLibrary.componentDefiner();
|
|
60
|
+
t.true(componentDefinition !== undefined);
|
|
61
|
+
t.true(componentDefinition.indexOf(`import '@webcomponents/scoped-custom-element-registry';`) > -1);
|
|
62
|
+
Object.keys(expected).forEach((component) => {
|
|
63
|
+
t.true(componentDefinition.indexOf(`import { ${expected[component]} } from '${process.cwd()}/components/${component}/src/${component}-component.js';`) > -1);
|
|
64
|
+
t.true(componentDefinition.indexOf(`customElements.define('muon-${component}', ${expected[component]});`) > -1);
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
componentsDefinitionMacro.title = (providedTitle, expected) => `${providedTitle} => ${Object.keys(expected)}`;
|
|
68
|
+
|
|
69
|
+
testRunner('componentDefiner', componentsDefinitionMacro, { card: 'Card', cta: 'Cta', detail: 'Detail', form: 'Form', icon: 'Icon', inputter: 'Inputter', image: 'Image' });
|
|
70
|
+
|
|
71
|
+
testRunner('getAliasPath glob', async (t) => {
|
|
72
|
+
const alias = utilsLibrary.getAliasPaths('glob');
|
|
73
|
+
|
|
74
|
+
t.deepEqual(alias, {
|
|
75
|
+
'@muon/components/*': [`${appRoot}/node_modules/@muonic/muon/components/*`],
|
|
76
|
+
'@muon/mixins/*': [`${appRoot}/node_modules/@muonic/muon/mixins/*`],
|
|
77
|
+
'@muon/directives/*': [`${appRoot}/node_modules/@muonic/muon/directives/*`],
|
|
78
|
+
'@muon/utils/*': [`${appRoot}/node_modules/@muonic/muon/utils/*`],
|
|
79
|
+
'@muon/tokens': [`${appRoot}/node_modules/@muonic/muon/build/tokens/es6/muon-tokens`]
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
testRunner('getAliasPath regex', async (t) => {
|
|
84
|
+
const alias = utilsLibrary.getAliasPaths('regex');
|
|
85
|
+
t.deepEqual(alias, [
|
|
86
|
+
{
|
|
87
|
+
find: /^@muon\/components\/(.*)$/,
|
|
88
|
+
replacement: '@muonic/muon/components/$1'
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
find: /^@muon\/mixins\/(.*)$/,
|
|
92
|
+
replacement: '@muonic/muon/mixins/$1'
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
find: /^@muon\/directives\/(.*)$/,
|
|
96
|
+
replacement: '@muonic/muon/directives/$1'
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
find: /^@muon\/utils\/(.*)$/,
|
|
100
|
+
replacement: '@muonic/muon/utils/$1'
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
find: /^@muon\/tokens$/,
|
|
104
|
+
replacement: '@muonic/muon/build/tokens/es6/muon-tokens'
|
|
105
|
+
}
|
|
106
|
+
]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
testRunner('getAliasPath invalid', async (t) => {
|
|
110
|
+
const alias = utilsLibrary.getAliasPaths('invalid');
|
|
111
|
+
t.true(alias === undefined);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
testRunner('getAliasPath config alias regex', async (t) => {
|
|
115
|
+
const stub = await esmock('../../../scripts/utils/index.mjs', {
|
|
116
|
+
'../../../scripts/utils/config.mjs': {
|
|
117
|
+
getConfig: (configFile) => JSON.parse(fs.readFileSync('tests/scripts/utils/muon.config.test.json').toString())
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
const alias = stub.getAliasPaths('regex');
|
|
121
|
+
t.true(alias !== undefined);
|
|
122
|
+
t.deepEqual(alias, [
|
|
123
|
+
{
|
|
124
|
+
find: /^@muon\/utils\/validation$/,
|
|
125
|
+
replacement: `${process.cwd()}/utils/validation`
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
find: /^@muon\/components\/(.*)$/,
|
|
129
|
+
replacement: '@muonic/muon/components/$1'
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
find: /^@muon\/mixins\/(.*)$/,
|
|
133
|
+
replacement: '@muonic/muon/mixins/$1'
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
find: /^@muon\/directives\/(.*)$/,
|
|
137
|
+
replacement: '@muonic/muon/directives/$1'
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
find: /^@muon\/utils\/(.*)$/,
|
|
141
|
+
replacement: '@muonic/muon/utils/$1'
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
find: /^@muon\/tokens$/,
|
|
145
|
+
replacement: '@muonic/muon/build/tokens/es6/muon-tokens'
|
|
146
|
+
}
|
|
147
|
+
]);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
testRunner('getAliasPath config alias glob', async (t) => {
|
|
151
|
+
const stub = await esmock('../../../scripts/utils/index.mjs', {
|
|
152
|
+
'../../../scripts/utils/config.mjs': {
|
|
153
|
+
getConfig: (configFile) => JSON.parse(fs.readFileSync('tests/scripts/utils/muon.config.test.json').toString())
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
const alias = stub.getAliasPaths('glob');
|
|
157
|
+
t.true(alias !== undefined);
|
|
158
|
+
t.deepEqual(alias, {
|
|
159
|
+
'@muon/utils/validation': ['./utils/validation'],
|
|
160
|
+
'@muon/components/*': [
|
|
161
|
+
`${appRoot}/node_modules/@muonic/muon/components/*`
|
|
162
|
+
],
|
|
163
|
+
'@muon/mixins/*': [
|
|
164
|
+
`${appRoot}/node_modules/@muonic/muon/mixins/*`
|
|
165
|
+
],
|
|
166
|
+
'@muon/directives/*': [
|
|
167
|
+
`${appRoot}/node_modules/@muonic/muon/directives/*`
|
|
168
|
+
],
|
|
169
|
+
'@muon/utils/*': [
|
|
170
|
+
`${appRoot}/node_modules/@muonic/muon/utils/*`
|
|
171
|
+
],
|
|
172
|
+
'@muon/tokens': [
|
|
173
|
+
`${appRoot}/node_modules/@muonic/muon/build/tokens/es6/muon-tokens`
|
|
174
|
+
]
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
testRunner('sourceFilesAnalyzer', async (t) => {
|
|
179
|
+
const result = await utilsLibrary.sourceFilesAnalyzer();
|
|
180
|
+
const jsonResult = JSON.parse(result);
|
|
181
|
+
|
|
182
|
+
const components = ['card', 'cta', 'detail', 'form', 'icon', 'image', 'inputter', 'inputter-detail'];
|
|
183
|
+
const propertiesMap = {
|
|
184
|
+
card: ['standardTemplate', 'image', 'alt', 'background', 'type'],
|
|
185
|
+
cta: ['href', 'standardTemplate', 'submitTemplate', 'resetTemplate', 'loading', 'loadingMessage', 'disabled', 'icon', 'type'],
|
|
186
|
+
detail: ['icon', 'standardTemplate', 'open', 'type'],
|
|
187
|
+
form: ['standardTemplate', 'type'],
|
|
188
|
+
icon: ['size', 'sizes', 'iconSize', 'standardTemplate', 'name', 'category', 'allSizes', 'url', 'describe', 'type'],
|
|
189
|
+
image: ['src', 'placeholderImage', 'standardTemplate', 'background', 'backgroundsize', 'alt', 'ratio', 'placeholder', 'loading', 'type'],
|
|
190
|
+
inputter: ['helper', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'type'],
|
|
191
|
+
'inputter-detail': ['icon', 'standardTemplate', 'open', 'type']
|
|
192
|
+
};
|
|
193
|
+
t.deepEqual(jsonResult.tags?.map((tag) => tag.name), components);
|
|
194
|
+
|
|
195
|
+
components.forEach((component) => {
|
|
196
|
+
t.deepEqual(jsonResult.tags.filter((tag) => tag.name === component)[0].properties?.map(
|
|
197
|
+
(property) => property.name), propertiesMap[component]);
|
|
198
|
+
});
|
|
199
|
+
jsonResult.tags?.map((tag) => {
|
|
200
|
+
t.true(tag.description !== undefined, `${tag.name} description is not present`);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
testRunner('sourceFilesAnalyzer error', async (t) => {
|
|
205
|
+
const stub = await esmock('../../../scripts/utils/index.mjs', {
|
|
206
|
+
'../../../scripts/utils/config.mjs': {
|
|
207
|
+
getConfig: (configFile) => JSON.parse(fs.readFileSync('tests/scripts/utils/muon.config.test.json').toString())
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
const sinonStub = sinon.stub(process, 'exit');
|
|
211
|
+
await stub.sourceFilesAnalyzer();
|
|
212
|
+
t.true(process.exit.called);
|
|
213
|
+
t.true(process.exit.calledWith(1));
|
|
214
|
+
sinonStub.restore();
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
testRunner('sourceFilesAnalyzer single file', async (t) => {
|
|
218
|
+
const stub = await esmock('../../../scripts/utils/index.mjs', {
|
|
219
|
+
'../../../scripts/utils/config.mjs': {
|
|
220
|
+
getConfig: (configFile) => JSON.parse(fs.readFileSync('tests/scripts/utils/single.component.config.json').toString())
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
const result = await stub.sourceFilesAnalyzer();
|
|
224
|
+
const jsonResult = JSON.parse(result);
|
|
225
|
+
|
|
226
|
+
const components = ['card'];
|
|
227
|
+
const propertiesMap = {
|
|
228
|
+
card: ['standardTemplate', 'image', 'alt', 'background', 'type'],
|
|
229
|
+
};
|
|
230
|
+
t.deepEqual(jsonResult.tags?.map((tag) => tag.name), components);
|
|
231
|
+
|
|
232
|
+
components.forEach((component) => {
|
|
233
|
+
t.deepEqual(jsonResult.tags.filter((tag) => tag.name === component)[0].properties?.map(
|
|
234
|
+
(property) => property.name), propertiesMap[component]);
|
|
235
|
+
});
|
|
236
|
+
jsonResult.tags?.map((tag) => {
|
|
237
|
+
t.true(tag.description !== undefined, `${tag.name} description is not present`);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
testRunner('create tokens', async (t) => {
|
|
242
|
+
await utilsLibrary.createTokens();
|
|
243
|
+
t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'css', 'mn-fonts.css')), 'font css file not exist');
|
|
244
|
+
t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'es6', 'muon-tokens-module.js')), 'muon-tokens-module.js don\'t exist');
|
|
245
|
+
t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'es6', 'muon-tokens.js')), 'muon-tokens.js don\'t exist');
|
|
246
|
+
t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'es6', 'muon-tokens.mjs')), 'muon-tokens.mjs don\'t exist');
|
|
247
|
+
t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'json', 'muon-tokens-reference.json')), 'muon-tokens-reference.json don\'t exist');
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
testRunner('getDestination', async (t) => {
|
|
251
|
+
const destination = utilsLibrary.getDestination();
|
|
252
|
+
t.is(destination, 'dist');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
testRunner('runner', async (t) => {
|
|
256
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
257
|
+
const __dirname = path.dirname(__filename);
|
|
258
|
+
utilsLibrary.runner(path.join(__dirname, 'test-runner.mjs'));
|
|
259
|
+
t.pass();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
testRunner('cleanup on rollup', async (t) => {
|
|
263
|
+
const destination = utilsLibrary.getDestination();
|
|
264
|
+
const cemPath = path.join(destination, 'custom-elements.json');
|
|
265
|
+
if (!fs.existsSync(destination)) {
|
|
266
|
+
fs.mkdirSync(destination);
|
|
267
|
+
}
|
|
268
|
+
fs.openSync(cemPath, 'w');
|
|
269
|
+
t.true(fs.existsSync(destination));
|
|
270
|
+
t.true(fs.existsSync(cemPath));
|
|
271
|
+
utilsLibrary.cleanup(destination, true);
|
|
272
|
+
t.true(fs.existsSync(destination));
|
|
273
|
+
t.false(fs.existsSync(cemPath));
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
testRunner('cleanup on serve', async (t) => {
|
|
277
|
+
const destination = utilsLibrary.getDestination();
|
|
278
|
+
if (!fs.existsSync(destination)) {
|
|
279
|
+
fs.mkdirSync(destination);
|
|
280
|
+
}
|
|
281
|
+
t.true(fs.existsSync(destination));
|
|
282
|
+
utilsLibrary.cleanup(destination);
|
|
283
|
+
t.true(fs.existsSync(destination));
|
|
284
|
+
});
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
const testRunner = require('ava');
|
|
2
|
-
const sinon = require('sinon');
|
|
3
|
-
const appRoot = require('app-root-path');
|
|
4
|
-
|
|
5
|
-
let utilsLibrary;
|
|
6
|
-
testRunner.before(async () => {
|
|
7
|
-
await import('../../../scripts/utils/index.mjs').then((utils) => {
|
|
8
|
-
utilsLibrary = utils;
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
testRunner('filterPathToCustomElements default', async (t) => {
|
|
13
|
-
const componentList = await utilsLibrary.filterPathToCustomElements('all');
|
|
14
|
-
t.is(componentList, '*');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
testRunner('filterPathToCustomElements default array', async (t) => {
|
|
18
|
-
const componentList = await utilsLibrary.filterPathToCustomElements(['all']);
|
|
19
|
-
t.is(componentList, '*');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
testRunner('filterPathToCustomElements single component', async (t) => {
|
|
23
|
-
const componentList = await utilsLibrary.filterPathToCustomElements('inputter');
|
|
24
|
-
t.is(componentList, 'inputter');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
testRunner('filterPathToCustomElements single component in array', async (t) => {
|
|
28
|
-
const componentList = await utilsLibrary.filterPathToCustomElements(['inputter']);
|
|
29
|
-
t.is(componentList, 'inputter');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
testRunner('filterPathToCustomElements multiple component', async (t) => {
|
|
33
|
-
const componentList = await utilsLibrary.filterPathToCustomElements(['inputter', 'image']);
|
|
34
|
-
t.is(componentList, '{inputter,image}');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
testRunner('getConfig default file and root', async (t) => {
|
|
38
|
-
const config = utilsLibrary.getConfig();
|
|
39
|
-
t.true(config !== undefined);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
testRunner('getConfig new file default root', async (t) => {
|
|
43
|
-
const config = utilsLibrary.getConfig('browserstack.json');
|
|
44
|
-
t.true(config !== undefined);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
testRunner('getConfig config file not exist', async (t) => {
|
|
48
|
-
sinon.stub(process, 'exit');
|
|
49
|
-
utilsLibrary.getConfig('test.json');
|
|
50
|
-
t.true(process.exit.called);
|
|
51
|
-
t.true(process.exit.calledWith(1));
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
testRunner('getConfig config file', async (t) => {
|
|
55
|
-
const config = utilsLibrary.getConfig('tests/scripts/utils/test.json');
|
|
56
|
-
t.true(config !== undefined);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const componentsDefinitionMacro = async (t, expected) => {
|
|
60
|
-
const componentDefinition = await utilsLibrary.componentDefiner();
|
|
61
|
-
t.true(componentDefinition !== undefined);
|
|
62
|
-
t.true(componentDefinition.indexOf(`import '@webcomponents/scoped-custom-element-registry';`) > -1);
|
|
63
|
-
Object.keys(expected).forEach((component) => {
|
|
64
|
-
t.true(componentDefinition.indexOf(`import { ${expected[component]} } from '${process.cwd()}/components/${component}/src/${component}-component.js';`) > -1);
|
|
65
|
-
t.true(componentDefinition.indexOf(`customElements.define('muon-${component}', ${expected[component]});`) > -1);
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
componentsDefinitionMacro.title = (providedTitle, expected) => `${providedTitle} => ${Object.keys(expected)}`;
|
|
69
|
-
|
|
70
|
-
testRunner('componentDefiner', componentsDefinitionMacro, { card: 'Card', cta: 'Cta', detail: 'Detail', form: 'Form', icon: 'Icon', inputter: 'Inputter', image: 'Image' });
|
|
71
|
-
|
|
72
|
-
testRunner('getAliasPath glob', async (t) => {
|
|
73
|
-
const alias = utilsLibrary.getAliasPaths('glob');
|
|
74
|
-
|
|
75
|
-
t.deepEqual(alias, {
|
|
76
|
-
'@muon/components/*': [`${appRoot}/node_modules/@muonic/muon/components/*`],
|
|
77
|
-
'@muon/mixins/*': [`${appRoot}/node_modules/@muonic/muon/mixins/*`],
|
|
78
|
-
'@muon/directives/*': [`${appRoot}/node_modules/@muonic/muon/directives/*`],
|
|
79
|
-
'@muon/utils/*': [`${appRoot}/node_modules/@muonic/muon/utils/*`],
|
|
80
|
-
'@muon/tokens': [`${appRoot}/node_modules/@muonic/muon/build/tokens/es6/muon-tokens`]
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
testRunner('getAliasPath regex', async (t) => {
|
|
85
|
-
const alias = utilsLibrary.getAliasPaths('regex');
|
|
86
|
-
t.deepEqual(alias, [
|
|
87
|
-
{
|
|
88
|
-
find: /^@muon\/components\/(.*)$/,
|
|
89
|
-
replacement: '@muonic/muon/components/$1'
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
find: /^@muon\/mixins\/(.*)$/,
|
|
93
|
-
replacement: '@muonic/muon/mixins/$1'
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
find: /^@muon\/directives\/(.*)$/,
|
|
97
|
-
replacement: '@muonic/muon/directives/$1'
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
find: /^@muon\/utils\/(.*)$/,
|
|
101
|
-
replacement: '@muonic/muon/utils/$1'
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
find: /^@muon\/tokens$/,
|
|
105
|
-
replacement: '@muonic/muon/build/tokens/es6/muon-tokens'
|
|
106
|
-
}
|
|
107
|
-
]);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
testRunner('sourceFilesAnalyzer', async (t) => {
|
|
111
|
-
const result = await utilsLibrary.sourceFilesAnalyzer();
|
|
112
|
-
const jsonResult = JSON.parse(result);
|
|
113
|
-
|
|
114
|
-
const components = ['card', 'cta', 'detail', 'form', 'icon', 'image', 'inputter', 'inputter-detail'];
|
|
115
|
-
const propertiesMap = {
|
|
116
|
-
card: ['standardTemplate', 'image', 'alt', 'background', 'type'],
|
|
117
|
-
cta: ['href', 'standardTemplate', 'submitTemplate', 'resetTemplate', 'loading', 'loadingMessage', 'disabled', 'icon', 'type'],
|
|
118
|
-
detail: ['icon', 'standardTemplate', 'open', 'type'],
|
|
119
|
-
form: ['standardTemplate', 'type'],
|
|
120
|
-
icon: ['size', 'sizes', 'iconSize', 'standardTemplate', 'name', 'category', 'allSizes', 'url', 'describe', 'type'],
|
|
121
|
-
image: ['src', 'placeholderImage', 'standardTemplate', 'background', 'backgroundsize', 'alt', 'ratio', 'placeholder', 'loading', 'type'],
|
|
122
|
-
inputter: ['helper', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'type'],
|
|
123
|
-
'inputter-detail': ['icon', 'standardTemplate', 'open', 'type']
|
|
124
|
-
};
|
|
125
|
-
t.deepEqual(jsonResult.tags?.map((tag) => tag.name), components);
|
|
126
|
-
|
|
127
|
-
components.forEach((component) => {
|
|
128
|
-
t.deepEqual(jsonResult.tags.filter((tag) => tag.name === component)[0].properties?.map(
|
|
129
|
-
(property) => property.name), propertiesMap[component]);
|
|
130
|
-
});
|
|
131
|
-
jsonResult.tags?.map((tag) => {
|
|
132
|
-
t.true(tag.description !== undefined, `${tag.name} description is not present`);
|
|
133
|
-
});
|
|
134
|
-
});
|