Skip to content

Commit

Permalink
Adds conditionally suggesting upgrading OUIF scss files. Closes #1468
Browse files Browse the repository at this point in the history
  • Loading branch information
waldekmastykarz committed Apr 11, 2020
1 parent e8c030a commit caf77e3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/o365/spfx/commands/project/project-upgrade.spec.ts
Expand Up @@ -1901,7 +1901,7 @@ describe(commands.PROJECT_UPGRADE, () => {
cmdInstance.action = command.action();
cmdInstance.action({ options: { toVersion: '1.9.1', output: 'json' } }, (err?: any) => {
const findings: Finding[] = log[0];
assert.equal(findings.length, 18);
assert.equal(findings.length, 17);
});
});

Expand Down
Expand Up @@ -36,7 +36,7 @@ describe('FN022002_SCSS_add_fabric_react', () => {
assert.equal(findings.length, 0);
});

it('returns notifications if import is missing', () => {
it('returns notifications if import is missing and no condition', () => {
rule = new FN022002_SCSS_add_fabric_react('~fabric-ui/react');
fileStub = sinon.stub(fs, 'readFileSync').returns('');
const project: Project = {
Expand All @@ -49,6 +49,33 @@ describe('FN022002_SCSS_add_fabric_react', () => {
assert.equal(findings.length, 1);
});

it('doesn\'t return notifications if import is missing but condition is not met', () => {
rule = new FN022002_SCSS_add_fabric_react('~fabric-ui/react', '~old-fabric-ui/react');

fileStub = sinon.stub(fs, 'readFileSync').returns('');
const project: Project = {
path: '/usr/tmp',
scssFiles: [
new ScssFile('some/path')
]
};
rule.visit(project, findings);
assert.equal(findings.length, 0);
});

it('returns notifications if import is missing and condition is met', () => {
rule = new FN022002_SCSS_add_fabric_react('~fabric-ui/react', '~old-fabric-ui/react');
fileStub = sinon.stub(fs, 'readFileSync').returns('~old-fabric-ui/react');
const project: Project = {
path: '/usr/tmp',
scssFiles: [
new ScssFile('some/path')
]
};
rule.visit(project, findings);
assert.equal(findings.length, 1);
});

it('doesn\'t return notifications if scss is not in react web part', () => {
rule = new FN022002_SCSS_add_fabric_react('~fabric-ui/react');
utilsStub.restore();
Expand Down Expand Up @@ -78,7 +105,7 @@ describe('FN022002_SCSS_add_fabric_react', () => {
assert.equal(findings.length, 0);
});

it('rule file name is empy', () => {
it('rule file name is empty', () => {
rule = new FN022002_SCSS_add_fabric_react('~fabric-ui/react');
fileStub = sinon.stub(fs, 'readFileSync').returns('');

Expand Down
Expand Up @@ -4,7 +4,7 @@ import { ScssRule } from "./ScssRule";
import { Occurrence, Utils } from "../";

export class FN022002_SCSS_add_fabric_react extends ScssRule {
constructor(private importValue: string) {
constructor(private importValue: string, private addIfContains?: string) {
super();
}

Expand Down Expand Up @@ -48,11 +48,14 @@ export class FN022002_SCSS_add_fabric_react extends ScssRule {

const occurrences: Occurrence[] = [];
project.scssFiles.forEach((file: ScssFile) => {
if ((file.source as string).indexOf(this.importValue) === -1) {
this.addOccurrence(this.resolution, file.path, project.path, occurrences);
const source: string = file.source as string;
if (source.indexOf(this.importValue) === -1) {
if (!this.addIfContains || source.indexOf(this.addIfContains) > -1) {
this.addOccurrence(this.resolution, file.path, project.path, occurrences);
}
}
});

if (occurrences.length > 0) {
this.addFindingWithOccurrences(occurrences, findings);
}
Expand Down
Expand Up @@ -47,5 +47,5 @@ module.exports = [
new FN001008_DEP_react('16.8.5'),
new FN001009_DEP_react_dom('16.8.5'),
new FN022001_SCSS_remove_fabric_react('~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss'),
new FN022002_SCSS_add_fabric_react('~office-ui-fabric-react/dist/sass/References.scss')
new FN022002_SCSS_add_fabric_react('~office-ui-fabric-react/dist/sass/References.scss', '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss')
];

0 comments on commit caf77e3

Please sign in to comment.