Skip to content

Commit

Permalink
fix(next): skip test files
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Dec 10, 2019
1 parent 9c2a256 commit 150d984
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 24 deletions.
20 changes: 9 additions & 11 deletions src/compiler_next/config/validate-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config, ConfigBundle, Diagnostic } from '../../declarations';
import { buildError, isBoolean, sortBy } from '@utils';
import { buildError, isBoolean, sortBy, buildWarn } from '@utils';
import { validateDevServer } from './validate-dev-server';
import { validateNamespace } from './validate-namespace';
import { validateOutputTargets } from './outputs';
Expand Down Expand Up @@ -115,17 +115,15 @@ export const validateConfig = (userConfig?: Config) => {
setBooleanConfig(config, 'generateDocs', 'docs', false);
setBooleanConfig(config, 'enableCache', 'cache', true);

// if (!Array.isArray(config.includeSrc)) {
// config.includeSrc = DEFAULT_INCLUDES.map(include => {
// return config.sys.path.join(config.srcDir, include);
// });
// }
if (config.excludeSrc) {
const warn = buildWarn(diagnostics);
warn.messageText = `"excludeSrc" is deprecated, use the "exclude" option in tsconfig.json`;
}

// if (!Array.isArray(config.excludeSrc)) {
// config.excludeSrc = DEFAULT_EXCLUDES.map(include => {
// return config.sys.path.join(config.srcDir, include);
// });
// }
if (config.includeSrc) {
const warn = buildWarn(diagnostics);
warn.messageText = `"includeSrc" is deprecated, use the "include" option in tsconfig.json`;
}

// set to true so it doesn't bother going through all this again on rebuilds
// config._isValidated = true;
Expand Down
22 changes: 17 additions & 5 deletions src/compiler_next/sys/typescript/typescript-patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,23 @@ const validateTsConfig = async (config: d.Config, diagnostics: d.Diagnostic[], i
diagnostics.push(loadTypeScriptDiagnostic(results.error));

} else if (results.config) {
if (hasSrcDirectoryInclude(results.config.include)) {
const warn = buildWarn(diagnostics);
warn.header = `tsconfig.json "include" required`;
warn.messageText = `In order for TypeScript to improve watch performance, it's recommended the "tsconfig.json" file should have the "include" property, with at least the app's "src" directory listed. For example: "include": ["src"]`;
}
const compilerOptions = results.config.compilerOptions;
if (hasSrcDirectoryInclude(results.config.include)) {
const warn = buildWarn(diagnostics);
warn.header = `tsconfig.json "include" required`;
warn.messageText = `In order for TypeScript to improve watch performance, it's recommended the "tsconfig.json" file should have the "include" property, with at least the app's "src" directory listed. For example: "include": ["src"]`;
}

const target = (compilerOptions.target ?? 'es5').toLowerCase();
if (['es3', 'es5', 'es2015', 'es2016'].includes(target)) {
const warn = buildWarn(diagnostics);
warn.messageText = `To improve bundling, it is always recommended to set the tsconfig.json “target” setting to "es2017". Note that the compiler will automatically handle transpilation for ES5-only browsers.`;
}

if (compilerOptions.module !== 'esnext' && !config._isTesting) {
const warn = buildWarn(diagnostics);
warn.messageText = `To improve bundling, it is always recommended to set the tsconfig.json “module” setting to “esnext”. Note that the compiler will automatically handle bundling both modern and legacy builds.`;
}
}

} catch (e) {
Expand Down
41 changes: 33 additions & 8 deletions src/compiler_next/sys/typescript/typescript-sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,34 @@ const patchTsSystemFileSystem = (config: d.Config, stencilSys: d.CompilerSystem,
// !p.includes('/@types/estree')
// ));

const skipFile = (readPath: string) => {
// filter e2e tests
if (readPath.includes('.e2e.') || readPath.includes('/e2e.')) {
// keep this test if it's an e2e file and we should be testing e2e
return true;
}

// filter spec tests
if (readPath.includes('.spec.') || readPath.includes('/spec.')) {
return true;
}
return false;
};

tsSys.createDirectory = (p) => stencilSys.mkdirSync(p);

tsSys.directoryExists = (p) => {
if (skipFile(p)) {
return false;
}
const s = inMemoryFs.statSync(p);
return s.isDirectory;
};

tsSys.fileExists = (p) => {
if (skipFile(p)) {
return false;
}
const s = inMemoryFs.statSync(p);
return s.isFile;
};
Expand All @@ -63,17 +83,19 @@ const patchTsSystemFileSystem = (config: d.Config, stencilSys: d.CompilerSystem,
depth--;

dirItems.forEach(dirItem => {
if (Array.isArray(extensions) && extensions.length > 0) {
if (extensions.some(ext => dirItem.endsWith(ext))) {
if (!skipFile(dirItem)) {
if (Array.isArray(extensions) && extensions.length > 0) {
if (extensions.some(ext => dirItem.endsWith(ext))) {
matchingPaths.add(dirItem);
}
} else {
matchingPaths.add(dirItem);
}
} else {
matchingPaths.add(dirItem);
}

const s = inMemoryFs.statSync(dirItem);
if (s && s.isDirectory) {
visitDirectory(matchingPaths, dirItem, extensions, depth);
const s = inMemoryFs.statSync(dirItem);
if (s && s.isDirectory) {
visitDirectory(matchingPaths, dirItem, extensions, depth);
}
}
});
};
Expand All @@ -88,6 +110,9 @@ const patchTsSystemFileSystem = (config: d.Config, stencilSys: d.CompilerSystem,
};

tsSys.readFile = (p) => {
if (skipFile(p)) {
return undefined;
}
let content = inMemoryFs.readFileSync(p, {useCache: false});

if (typeof content !== 'string' && (p.startsWith('https:') || p.startsWith('http:'))) {
Expand Down
6 changes: 6 additions & 0 deletions src/declarations/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export interface StencilConfig {
* from the build process.
*
* The defaults are meant to exclude possible test files that you would not want to include in your final build.
*
* @deprecated Use the "exclude" option in tsconfig.json`;
*/
excludeSrc?: string[];

Expand Down Expand Up @@ -180,6 +182,10 @@ export interface StencilConfig {
*/
maxConcurrentTasksPerWorker?: number;
preamble?: string;

/**
* @deprecated Use the "include" option in tsconfig.json`;
*/
includeSrc?: string[];

entryComponentsHint?: string[];
Expand Down

0 comments on commit 150d984

Please sign in to comment.