Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing mocks, update script to catch more #9

Merged
merged 2 commits into from Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 47 additions & 20 deletions scripts/checkLightningMocks.js
Expand Up @@ -17,12 +17,23 @@ const path = require('path');

const pathToMocks = path.join(__dirname, '..', 'src', 'lightning-mocks');
const lightningNamespaces = [ 'lightning', 'interop' ];
/*
* some components have multiple html files in the bundle and dynamically
* which to load in the render() method. Map to the most standard or default
* html to get the slot count.
*/
const dynamicHtmlMapper = {
'tile': 'standardTile',
'progressStep': 'base',
}
const pathToComponents = process.argv[2];

function checkIsExposed(bundleDir, file) {
const metaXmlPath = path.join(bundleDir, file + '.js-meta.xml');
const metaXml = fs.existsSync(metaXmlPath) && fs.readFileSync(metaXmlPath, 'utf8');
return metaXml && metaXml.indexOf('<isExposed>true</isExposed>') !== -1;
return metaXml
&& metaXml.indexOf('<isExposed>true</isExposed>') !== -1
&& metaXml.indexOf('</minApiVersion>') !== -1;
}

function getSlotCount(htmlPath) {
Expand All @@ -33,57 +44,73 @@ function getSlotCount(htmlPath) {
return slotCount;
}

function getHtmlPath(base, fileName) {
// we don't use the dynamic html files in the mocks
if (base.indexOf('lightning-mocks') === -1 && dynamicHtmlMapper[fileName]) {
fileName = dynamicHtmlMapper[fileName];
}
return path.join(base, fileName + '.html');
}

if (!pathToComponents) {
console.log('Error: Missing path to lightning modules directory. Usage: "node checkLightningMocks.js ~/path/to/lightning/modules"');
process.exit(1);
}

// exposed lightning components with an html file and at least one <slot> present in markup
let matches = [];
let exposed = [];
lightningNamespaces.forEach(ns => {
const nsDir = path.join(pathToComponents, ns);
fs.readdirSync(nsDir).forEach(file => {
const bundleDir = path.join(nsDir, file);
const htmlPath = path.join(bundleDir, file + '.html');
const hasHtml = fs.existsSync(htmlPath);
const isExposed = checkIsExposed(bundleDir, file);
if (hasHtml && isExposed) {
const slots = getSlotCount(htmlPath);
if (slots > 0) {
matches.push({ file, slots });
}

if (!isExposed) {
return;
}

const htmlPath = getHtmlPath(bundleDir, file);
const hasHtml = fs.existsSync(htmlPath);
const slotCount = hasHtml && getSlotCount(htmlPath) || 0;
exposed.push({
file,
slotCount,
});
});
});

let missingMocks = [];
let missingSlots = [];
matches.forEach(entry => {
exposed.forEach(entry => {
const file = entry.file;
const bundleDir = path.join(pathToMocks, file);
const mocksDir = path.join(pathToMocks, file);

if (!fs.existsSync(bundleDir)) {
if (!fs.existsSync(mocksDir)) {
missingMocks.push(file);
return;
}

const htmlPath = path.join(bundleDir, file + '.html');
const slots = getSlotCount(htmlPath);
if (slots !== entry.slots) {
const htmlPath = getHtmlPath(mocksDir, file);
const slotCount = getSlotCount(htmlPath);
if (slotCount !== entry.slotCount) {
missingSlots.push({
file,
expectedSlotCount: entry.slots,
actualSlotCount: slots,
expectedSlotCount: entry.slotCount,
actualSlotCount: slotCount,
});
}

});

let exitCode = 0;
if (missingMocks.length > 0) {
console.log('Missing lightning mocks: ', missingMocks);
process.exit(1);
exitCode = 1;
}

if (missingSlots.length > 0) {
console.log('Missing slots on the following mocks: ', missingSlots);
process.exit(1);
exitCode = 1;
}

console.log('Exiting with exit code ', exitCode);
process.exit(exitCode);
7 changes: 7 additions & 0 deletions src/lightning-mocks/carouselImage/carouselImage.html
@@ -0,0 +1,7 @@
<!--
Copyright (c) 2018, salesforce.com, inc.
All rights reserved.
SPDX-License-Identifier: MIT
For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
-->
<template></template>
16 changes: 16 additions & 0 deletions src/lightning-mocks/carouselImage/carouselImage.js
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { LightningElement, api } from 'lwc';

export default class CarouselImage extends LightningElement {
@api src
@api header
@api description
@api alternativeText
@api href

}
14 changes: 14 additions & 0 deletions src/lightning-mocks/configProvider/configProvider.js
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
export default configProviderService = jest.fn();
export const getPathPrefix = jest.fn();
export const getToken = jest.fn();
export const getLocale = jest.fn();
export const getFormFactor = jest.fn();
export const getLocalizationService = jest.fn();
export const sanitizeDOM = jest.fn();
export const getCoreInfo = jest.fn();
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
export const baseNavigation = superclass => {
return class extends superclass {
@api keyboardMode
@api focus
[updateActionables]() {}
[handleArrowKeyDown]() {}
[handleArrowLeft]() {}
[handleArrowRight]() {}
[handleTabKey]() {}
[getActiveElement]() {}
[moveToPreviousOf]() {}
[moveToNextOf]() {}
};
};
7 changes: 7 additions & 0 deletions src/lightning-mocks/menuDivider/menuDivider.html
@@ -0,0 +1,7 @@
<!--
Copyright (c) 2018, salesforce.com, inc.
All rights reserved.
SPDX-License-Identifier: MIT
For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
-->
<template></template>
12 changes: 12 additions & 0 deletions src/lightning-mocks/menuDivider/menuDivider.js
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { LightningElement, api } from 'lwc';

export default class MenuDivider extends LightningElement {
@api variant

}
7 changes: 7 additions & 0 deletions src/lightning-mocks/menuSubheader/menuSubheader.html
@@ -0,0 +1,7 @@
<!--
Copyright (c) 2018, salesforce.com, inc.
All rights reserved.
SPDX-License-Identifier: MIT
For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
-->
<template></template>
12 changes: 12 additions & 0 deletions src/lightning-mocks/menuSubheader/menuSubheader.js
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { LightningElement, api } from 'lwc';

export default class MenuSubheader extends LightningElement {
@api label

}
7 changes: 7 additions & 0 deletions src/lightning-mocks/messages/messages.html
@@ -0,0 +1,7 @@
<!--
Copyright (c) 2018, salesforce.com, inc.
All rights reserved.
SPDX-License-Identifier: MIT
For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
-->
<template></template>
12 changes: 12 additions & 0 deletions src/lightning-mocks/messages/messages.js
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { LightningElement, api } from 'lwc';

export default class Messages extends LightningElement {
@api setError
@api error
}
11 changes: 3 additions & 8 deletions src/lightning-mocks/navigation/navigation.js
Expand Up @@ -10,14 +10,9 @@ const Navigate = Symbol("Navigate");
const GenerateUrl = Symbol("GenerateUrl");
export const NavigationMixin = (Base) => {
return class extends Base {
[Navigate](pageReference, replace) {
//getNavService(this).navigateTo(pageReference, {replace});
}

[GenerateUrl](pageReference) {
//return getNavService(this).generateUrl(pageReference);
}
[Navigate](pageReference, replace) {}
[GenerateUrl](pageReference) {}
};
};
NavigationMixin.Navigate = Navigate;
NavigationMixin.GenerateUrl = GenerateUrl;
NavigationMixin.GenerateUrl = GenerateUrl;
@@ -0,0 +1,8 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
export const loadStyle = jest.fn();
export const loadScript = jest.fn();
7 changes: 7 additions & 0 deletions src/lightning-mocks/progressStep/progressStep.html
@@ -0,0 +1,7 @@
<!--
Copyright (c) 2018, salesforce.com, inc.
All rights reserved.
SPDX-License-Identifier: MIT
For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
-->
<template></template>
13 changes: 13 additions & 0 deletions src/lightning-mocks/progressStep/progressStep.js
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { LightningElement, api } from 'lwc';

export default class ProgressStep extends LightningElement {
@api label
@api value

}