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

Manual test server will parse builds #642

Merged
merged 1 commit into from
May 25, 2020
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
28 changes: 18 additions & 10 deletions packages/ckeditor5-dev-tests/lib/utils/getrelativefilepath.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@

'use strict';

const path = require( 'path' );

/**
* Get a path to a source file which will uniquely identify this file in
* a build directory, once all packages are gathered together.
*
* In order to do that, everything up to `ckeditor5?-packageName` is removed:
* /work/space/ckeditor5/tests/manual/foo.js -> ckeditor5/tests/manual/foo.js
* /work/space/ckeditor/tests/manual/foo.js -> ckeditor/tests/manual/foo.js
* /work/space/ckeditor5-foo/tests/manual/foo.js -> ckeditor5-foo/tests/manual/foo.js
* /work/space/ckeditor-foo/tests/manual/foo.js -> ckeditor-foo/tests/manual/foo.js
* E.g.:
* - /work/space/ckeditor5/tests/manual/foo.js -> ckeditor5/tests/manual/foo.js
* - /work/space/ckeditor/tests/manual/foo.js -> ckeditor/tests/manual/foo.js
* - /work/space/packages/ckeditor5-foo/tests/manual/foo.js -> ckeditor5-foo/tests/manual/foo.js
* - /work/space/packages/ckeditor-foo/tests/manual/foo.js -> ckeditor-foo/tests/manual/foo.js
*
* @param {String} filePath
* @param {String} [cwd=process.cwd()]
* @returns {String}
*/
module.exports = function getRelativeFilePath( filePath ) {
return filePath.replace( /^.+[/\\]ckeditor(5)?(-)?/, ( ...match ) => {
const ckeditor = match[ 1 ] ? 'ckeditor5' : 'ckeditor';
module.exports = function getRelativeFilePath( filePath, cwd = process.cwd() ) {
// The path ends with the directory separator.
const relativePath = filePath.replace( cwd, '' ).slice( 1 );

// A package.
if ( relativePath.startsWith( 'packages' ) ) {
return relativePath.replace( 'packages', '' ).slice( 1 );
}

return match[ 2 ] ? `${ ckeditor }-` : ckeditor;
} );
// The main repository.
return path.join( 'ckeditor5', relativePath );
};
110 changes: 82 additions & 28 deletions packages/ckeditor5-dev-tests/tests/utils/getrelativefilepath.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

'use strict';

const path = require( 'path' );
const sinon = require( 'sinon' );
const { expect } = require( 'chai' );

describe( 'dev-tests/utils', () => {
Expand All @@ -15,71 +17,123 @@ describe( 'dev-tests/utils', () => {
} );

describe( 'getRelativeFilePath()', () => {
let sandbox;

beforeEach( () => {
sandbox = sinon.createSandbox();
} );

afterEach( () => {
sandbox.restore();
} );

describe( 'Unix paths', () => {
beforeEach( () => {
sandbox.stub( path, 'join' ).callsFake( ( ...args ) => args.join( '/' ) );
} );

it( 'returns path which starts with package name (simple check)', () => {
checkPath( '/work/space/ckeditor5-foo/tests/manual/foo.js', 'ckeditor5-foo/tests/manual/foo.js' );
sandbox.stub( process, 'cwd' ).returns( '/Users/foo' );

checkPath( '/Users/foo/packages/ckeditor5-foo/tests/manual/foo.js', 'ckeditor5-foo/tests/manual/foo.js' );
} );

it( 'returns path which starts with package name (workspace directory looks like package name)', () => {
sandbox.stub( process, 'cwd' ).returns( '/Users/foo/ckeditor5-workspace/ckeditor5' );

checkPath(
'/Users/foo/ckeditor5-workspace/ckeditor5/packages/ckeditor5-foo/tests/manual/foo.js',
'ckeditor5-foo/tests/manual/foo.js'
);
} );

it( 'returns path which starts with package name (nested dependencies)', () => {
checkPath(
'/home/foo/ckeditor5/packages/ckeditor5-build-classic/node_modules/@ckeditor/ckeditor5-foo/tests/manual/foo.js',
'ckeditor5-foo/tests/manual/foo.js'
);
} );
it( 'returns a proper path for "ckeditor-" prefix', () => {
sandbox.stub( process, 'cwd' ).returns( '/work/space' );

it( 'returns path which starts with package name (combined workspace looks like package and nested dependencies)', () => {
/* eslint-disable max-len */
checkPath(
'/Users/foo/ckeditor5-workspace/ckeditor5/ckeditor5-build-classic/node_modules/@ckeditor/ckeditor5-foo/tests/manual/foo.js',
'ckeditor5-foo/tests/manual/foo.js'
);
/* eslint-enable max-len */
checkPath( '/work/space/packages/ckeditor-foo/tests/manual/foo.js', 'ckeditor-foo/tests/manual/foo.js' );
} );

it( 'returns a proper path for "ckeditor-" prefix', () => {
checkPath( '/work/space/ckeditor-foo/tests/manual/foo.js', 'ckeditor-foo/tests/manual/foo.js' );
it( 'returns a proper path for "ckeditor-" prefix and "ckeditor.js" file', () => {
sandbox.stub( process, 'cwd' ).returns( '/work/space' );

checkPath( '/work/space/packages/ckeditor-foo/tests/manual/ckeditor.js', 'ckeditor-foo/tests/manual/ckeditor.js' );
} );

it( 'returns a proper path to from the main (root) package', () => {
checkPath( '/work/space/ckeditor5/tests/manual/foo.js', 'ckeditor5/tests/manual/foo.js' );
sandbox.stub( process, 'cwd' ).returns( '/work/space' );
checkPath( '/work/space/packages/ckeditor5/tests/manual/foo.js', 'ckeditor5/tests/manual/foo.js' );
} );

it( 'returns a proper path for "ckeditor5.js" file', () => {
sandbox.stub( process, 'cwd' ).returns( '/work/space' );
checkPath(
'/work/space/packages/ckeditor5-build-a/tests/manual/ckeditor5.js',
'ckeditor5-build-a/tests/manual/ckeditor5.js'
);
} );

it( 'returns a proper path for "ckeditor.js" file', () => {
sandbox.stub( process, 'cwd' ).returns( '/work/space' );
checkPath(
'/work/space/packages/ckeditor5-build-a/tests/manual/ckeditor.js',
'ckeditor5-build-a/tests/manual/ckeditor.js' );
} );
} );

describe( 'Windows paths', () => {
beforeEach( () => {
sandbox.stub( path, 'join' ).callsFake( ( ...args ) => args.join( '\\' ) );
} );

it( 'returns path which starts with package name (simple check)', () => {
checkPath( 'C:\\work\\space\\ckeditor5-foo\\tests\\manual\\foo.js', 'ckeditor5-foo\\tests\\manual\\foo.js' );
sandbox.stub( process, 'cwd' ).returns( 'C:\\work\\space' );

checkPath( 'C:\\work\\space\\packages\\ckeditor5-foo\\tests\\manual\\foo.js', 'ckeditor5-foo\\tests\\manual\\foo.js' );
} );

it( 'returns path which starts with package name (workspace directory looks like package name)', () => {
sandbox.stub( process, 'cwd' ).returns( 'C:\\Document and settings\\foo\\ckeditor5-workspace\\ckeditor5' );

checkPath(
'C:\\Document and settings\\foo\\ckeditor5-workspace\\ckeditor5\\packages\\ckeditor5-foo\\tests\\manual\\foo.js',
'ckeditor5-foo\\tests\\manual\\foo.js'
);
} );

it( 'returns path which starts with package name (nested dependencies)', () => {
/* eslint-disable max-len */
it( 'returns a proper path for "ckeditor-" prefix', () => {
sandbox.stub( process, 'cwd' ).returns( 'C:\\work\\space' );

checkPath( 'C:\\work\\space\\packages\\ckeditor-foo\\tests\\manual\\foo.js', 'ckeditor-foo\\tests\\manual\\foo.js' );
} );

it( 'returns a proper path for "ckeditor-" prefix and "ckeditor.js" file', () => {
sandbox.stub( process, 'cwd' ).returns( 'C:\\work\\space' );

checkPath(
'C:\\work\\space\\packages\\ckeditor-foo\\tests\\manual\\ckeditor.js',
'ckeditor-foo\\tests\\manual\\ckeditor.js'
);
} );

it( 'returns a proper path to from the main (root) package', () => {
sandbox.stub( process, 'cwd' ).returns( 'C:\\work\\space' );
checkPath( 'C:\\work\\space\\tests\\manual\\foo.js', 'ckeditor5\\tests\\manual\\foo.js' );
} );

it( 'returns a proper path for "ckeditor5.js" file', () => {
sandbox.stub( process, 'cwd' ).returns( 'C:\\work\\space' );
checkPath(
'C:\\Document and settings\\ckeditor5\\packages\\ckeditor5-build-classic\\node_modules\\@ckeditor\\ckeditor5-foo\\tests\\manual\\foo.js',
'ckeditor5-foo\\tests\\manual\\foo.js'
'C:\\work\\space\\packages\\ckeditor5-build-a\\tests\\manual\\ckeditor5.js',
'ckeditor5-build-a\\tests\\manual\\ckeditor5.js'
);
/* eslint-enable max-len */
} );

it( 'returns path which starts with package name (combined workspace looks like package and nested dependencies)', () => {
/* eslint-disable max-len */
it( 'returns a proper path for "ckeditor.js" file', () => {
sandbox.stub( process, 'cwd' ).returns( 'C:\\work\\space' );
checkPath(
'C:\\Users\\foo\\ckeditor5-workspace\\ckeditor5\\ckeditor5-build-classic\\node_modules\\@ckeditor\\ckeditor5-foo\\tests\\manual\\foo.js',
'ckeditor5-foo\\tests\\manual\\foo.js'
'C:\\work\\space\\packages\\ckeditor5-build-a\\tests\\manual\\ckeditor.js',
'ckeditor5-build-a\\tests\\manual\\ckeditor.js'
);
/* eslint-enable max-len */
} );
} );
} );
Expand Down