Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog


<!--## Unreleased -->
## Unreleased
* Fix `test` bug which broke Windows support relating to path delimeters.
<!-- Add new, unreleased items here. -->

## v1.7.0-pre.17 [05-03-2018]
Expand Down
1 change: 1 addition & 0 deletions packages/web-component-tester/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
* Dropped support for node v6. This is a soft break, as we aren't
making any changes that are known to break node v6, but we're no longer testing against it. See our [node version support policy](https://www.polymer-project.org/2.0/docs/tools/node-support)
for details.
* Fix path delimiter bug which broke Windows support.
<!-- Add new, unreleased items here. -->

## 6.6.0-pre.5 - 2018-04-12
Expand Down
55 changes: 20 additions & 35 deletions packages/web-component-tester/runner/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,14 @@ export function getPackageName(options: Config): string|undefined {
}

/**
* Truncates the path to the slash after the last occurrence of the given
* package name.
*
* @param directory Name of directory
* @param pathName Path to be truncated
* Return the root package directory of the given NPM package.
*/
export function truncatePathToDir(directory: string, pathName: string): string|
null {
const delimitedDir = `/${directory}/`;
const lastDirOccurrence = pathName.lastIndexOf(delimitedDir);
if (lastDirOccurrence === -1) {
return null;
}
return pathName.substr(0, lastDirOccurrence + delimitedDir.length);
function resolvePackageDir(
packageName: string, opts?: resolve.SyncOpts): string {
// package.json files are always in the root directory of a package, so we can
// resolve that and then drop the filename.
return path.dirname(
resolve.sync(path.join(packageName, 'package.json'), opts));
}

/**
Expand All @@ -175,43 +169,34 @@ export function truncatePathToDir(directory: string, pathName: string): string|
*/
export function resolveWctNpmEntrypointNames(
config: Config, npmPackages: NPMPackage[]): string[] {
// grab from CLI flag defaults to wct-browser-legacy
let wctPackageName = config.wctPackageName;

if (wctPackageName === undefined) {
wctPackageName = 'wct-browser-legacy';
}

let absoluteBrowserPath;

let wctPackageRoot;
try {
absoluteBrowserPath = resolve.sync(wctPackageName, {basedir: config.root});
wctPackageRoot = resolvePackageDir(wctPackageName, {basedir: config.root});
} catch {
throw new Error(
`${wctPackageName} not installed. Please change --wct-package-name` +
` flag or install the package.`);
}

// We want to find and inject dependencies WCT relies on not the local
// package or its dependencies' dependencies
const absoluteWCTRoot =
truncatePathToDir(wctPackageName, absoluteBrowserPath);
// We want to find and inject WCT's version of these dependencies, not the
// version from the package being tested.
const resolvedEntrypoints: string[] = [];
const rootNodeModules = path.join(config.root, 'node_modules');

for (const npmPackage of npmPackages) {
const absoluteNpmMainPath =
resolve.sync(npmPackage.name, {basedir: absoluteWCTRoot});

const absoluteBasePath =
truncatePathToDir(npmPackage.name, absoluteNpmMainPath);

// Find path relative to our testing element's node_modules
const nodeModulesDir = path.posix.join(config.root, 'node_modules');
const relativeBasePath =
path.posix.relative(nodeModulesDir, absoluteBasePath);

resolvedEntrypoints.push(
path.posix.join(relativeBasePath, npmPackage.jsEntrypoint));
const absoluteFilepath = resolve.sync(
path.join(npmPackage.name, npmPackage.jsEntrypoint),
{basedir: wctPackageRoot});
const relativeFilepath = path.relative(rootNodeModules, absoluteFilepath);
const relativeUrl = (process.platform === 'win32') ?
relativeFilepath.replace(/\\/g, '/') :
relativeFilepath;
resolvedEntrypoints.push(relativeUrl);
}

return resolvedEntrypoints;
Expand Down