Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl committed Sep 21, 2016
1 parent 5be71ef commit ccab53a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
17 changes: 10 additions & 7 deletions scripts/ci/forbidden-identifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const blocked_statements = [
];

const sourceFolders = ['./src', './e2e'];
const scopePackages = glob('src/lib/*');
const libRoot = 'src/lib';
const blockedRegex = new RegExp(blocked_statements.join('|'), 'g');
const importRegex = /from\s+'(.*)';/g;

Expand Down Expand Up @@ -58,7 +58,9 @@ findTestFiles()
lineCount++;

let matches = line.match(blockedRegex);
let scopeImport = isRelativeScopeImport(fileName, line);
let scopeImport = path.relative(libRoot, fileName).startsWith('..')
? isRelativeScopeImport(fileName, line)
: false;

if (matches || scopeImport) {

Expand Down Expand Up @@ -155,6 +157,10 @@ function findChangedFiles() {
* @param line Line to be checked.
*/
function isRelativeScopeImport(fileName, line) {
if (fileName.startsWith(libRoot)) {
return false;
}

let importMatch = importRegex.exec(line);

// We have to reset the last index of the import regex, otherwise we
Expand Down Expand Up @@ -184,8 +190,7 @@ function isRelativeScopeImport(fileName, line) {
if (fileScope.path !== importScope.path) {

// Creates a valid import statement, which uses the correct scope package.
let importFilePath = path.relative(importScope.path, importPath);
let validImportPath = `@angular/material/${importScope.name}/${importFilePath}`;
let validImportPath = `@angular/material`;

return {
fileScope: fileScope.name,
Expand All @@ -200,9 +205,7 @@ function isRelativeScopeImport(fileName, line) {
filePath = path.normalize(filePath);

// Iterate through all scope paths and try to find them inside of the file path.
var scopePath = scopePackages
.filter(scope => filePath.indexOf(path.normalize(scope)) !== -1)
.pop();
var scopePath = filePath.indexOf(path.normalize(libRoot)) == -1 ? libRoot : filePath;

// Return an object containing the name of the scope and the associated path.
return {
Expand Down
14 changes: 5 additions & 9 deletions tools/gulp/tasks/unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ gulp.task(':test:deps', sequenceTask(
[
':build:test:vendor',
':build:components:assets',
':build:components:scss',
':build:components:spec',
':build:components:inline',
':watch:components:spec',
]
));
Expand All @@ -39,12 +39,8 @@ gulp.task('test', [':test:deps'], (done: () => void) => {
});

gulp.task('test:single-run', [':test:deps'], (done: () => void) => {
runSequence(
':inline-resources',
() => {
new karma.Server({
configFile: path.join(PROJECT_ROOT, 'test/karma.conf.js'),
singleRun: true
}, done).start();
});
new karma.Server({
configFile: path.join(PROJECT_ROOT, 'test/karma.conf.js'),
singleRun: true
}, done).start();
});

0 comments on commit ccab53a

Please sign in to comment.