Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Aug 29, 2024
1 parent 848ff18 commit 7739dd0
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 759 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module.exports = function parseArguments( args ) {
}

const cwd = process.cwd();
const shouldCheckExternalDirectory = tools.isDirectory( path.join( cwd, 'external' ) );
const shouldCheckExternalDirectory = isDirectory( path.join( cwd, 'external' ) );

if ( !shouldCheckExternalDirectory ) {
log.warning( 'The `external/` directory does not exist. Only the root repository will be checked.' );
Expand All @@ -172,8 +172,10 @@ module.exports = function parseArguments( args ) {
const files = new Set( options.files );

for ( const repositoryName of options.repositories ) {
const cwdPackageJson = require( path.join( cwd, 'package.json' ) );

// Check the main repository.
if ( repositoryName === tools.readPackageName( cwd ) ) {
if ( repositoryName === cwdPackageJson.name ) {
addPackagesToCollection( files, path.join( cwd, 'packages' ) );

continue;
Expand All @@ -187,7 +189,7 @@ module.exports = function parseArguments( args ) {
const externalRepositoryPath = path.join( cwd, 'external', repositoryName );

// Check the "external" directory.
if ( tools.isDirectory( externalRepositoryPath ) ) {
if ( isDirectory( externalRepositoryPath ) ) {
addPackagesToCollection( files, path.join( externalRepositoryPath, 'packages' ) );
} else {
log.warning( `Did not find the repository "${ repositoryName }" in the root repository or the "external/" directory.` );
Expand Down Expand Up @@ -252,4 +254,17 @@ module.exports = function parseArguments( args ) {
} )
.join( '' );
}

/**
* @param {String} path
* @returns {Boolean}
*/
function isDirectory( path ) {
try {
return fs.statSync( path ).isDirectory();
} catch ( e ) {
return false;
}
}
};

Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,67 @@

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

const originalPosixJoin = path.posix.join;

describe( 'parseArguments()', () => {
let parseArguments, sandbox, stubs;
let parseArguments, sandbox, stubs, packageName;

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

mockery.enable( {
useCleanCache: true,
warnOnReplace: false,
warnOnUnregistered: false
} );

stubs = {
cwd: sandbox.stub( process, 'cwd' ).callsFake( () => '/' ),
existsSync: sandbox.stub( fs, 'existsSync' ),
tools: {
isDirectory: sandbox.stub(),
readPackageName: sandbox.stub(),
getDirectories: sandbox.stub()
},
logger: {
warning: sandbox.stub()
},
fs: {
statSync: sandbox.stub()
},
// To force unix paths in tests.
pathJoin: sandbox.stub( path, 'join' ).callsFake( ( ...chunks ) => originalPosixJoin( ...chunks ) )
};

stubs.cwd.returns( '/home/project' );

packageName = 'ckeditor5';

mockery.registerMock( '/home/project/package.json', {
get name() {
return packageName;
}
} );

// mockery.registerMock( 'fs', stubs.fs );

parseArguments = proxyquire( '../../../lib/utils/automated-tests/parsearguments', {
'@ckeditor/ckeditor5-dev-utils': {
logger() {
return stubs.logger;
},
tools: stubs.tools
}
},
'fs': stubs.fs
} );
} );

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

it( 'replaces kebab-case strings with camelCase values', () => {
Expand Down Expand Up @@ -172,10 +194,10 @@ describe( 'parseArguments()', () => {
'returns an array of packages to tests when `--repositories` is specified ' +
'(root directory check)',
() => {
stubs.cwd.returns( '/home/project' );
packageName = 'ckeditor5';

stubs.fs.statSync.withArgs( '/home/project/external' ).throws( 'ENOENT: no such file or directory' );

stubs.tools.isDirectory.withArgs( '/home/project/external' ).returns( false );
stubs.tools.readPackageName.withArgs( '/home/project' ).returns( 'ckeditor5' );
stubs.tools.getDirectories.withArgs( '/home/project/packages' ).returns( [
'ckeditor5-core',
'ckeditor5-engine'
Expand All @@ -199,12 +221,9 @@ describe( 'parseArguments()', () => {
'returns an array of packages to tests when `--repositories` is specified ' +
'(external directory check)',
() => {
stubs.cwd.returns( '/home/project' );
packageName = 'foo';

stubs.tools.isDirectory.withArgs( '/home/project/external' ).returns( true );
stubs.tools.isDirectory.withArgs( '/home/project/external/ckeditor5' ).returns( true );

stubs.tools.readPackageName.withArgs( '/home/project' ).returns( 'foo' );
stubs.fs.statSync.returns( { isDirectory: () => true } );
stubs.tools.getDirectories.withArgs( '/home/project/external/ckeditor5/packages' ).returns( [
'ckeditor5-core',
'ckeditor5-engine'
Expand All @@ -216,7 +235,6 @@ describe( 'parseArguments()', () => {
] );

expect( options.files ).to.deep.equal( [ 'core', 'engine' ] );

expect( stubs.logger.warning.callCount ).to.equal( 0 );
}
);
Expand All @@ -225,12 +243,10 @@ describe( 'parseArguments()', () => {
'returns an array of packages to tests when `--repositories` is specified ' +
'(external directory check, specified repository does not exist)',
() => {
stubs.cwd.returns( '/home/project' );
packageName = 'foo';

stubs.tools.isDirectory.withArgs( '/home/project/external' ).returns( true );
stubs.tools.isDirectory.withArgs( '/home/project/external/ckeditor5' ).returns( false );

stubs.tools.readPackageName.withArgs( '/home/project' ).returns( 'foo' );
stubs.fs.statSync.withArgs( '/home/project/external' ).returns( { isDirectory: () => true } );
stubs.fs.statSync.withArgs( '/home/project/external/ckeditor5' ).throws( 'ENOENT: no such file or directory' );

const options = parseArguments( [
'--repositories',
Expand All @@ -250,11 +266,9 @@ describe( 'parseArguments()', () => {
'returns an array of packages (unique list) to tests when `--repositories` is specified ' +
'(root directory check + `--files` specified)',
() => {
stubs.cwd.returns( '/home/project' );

stubs.tools.isDirectory.withArgs( '/home/project/external' ).returns( true );
packageName = 'ckeditor5';

stubs.tools.readPackageName.withArgs( '/home/project' ).returns( 'ckeditor5' );
stubs.fs.statSync.withArgs( '/home/project/external' ).returns( { isDirectory: () => true } );
stubs.tools.getDirectories.withArgs( '/home/project/packages' ).returns( [
'ckeditor5-core',
'ckeditor5-engine',
Expand All @@ -276,12 +290,11 @@ describe( 'parseArguments()', () => {
'returns an array of packages to tests when `--repositories` is specified ' +
'(root and external directories check)',
() => {
stubs.cwd.returns( '/home/project' );
packageName = 'ckeditor5';

stubs.tools.isDirectory.withArgs( '/home/project/external' ).returns( true );
stubs.tools.isDirectory.withArgs( '/home/project/external/foo' ).returns( true );
stubs.tools.isDirectory.withArgs( '/home/project/external/bar' ).returns( true );
stubs.tools.readPackageName.withArgs( '/home/project' ).returns( 'ckeditor5' );
stubs.fs.statSync.withArgs( '/home/project/external' ).returns( { isDirectory: () => true } );
stubs.fs.statSync.withArgs( '/home/project/external/foo' ).returns( { isDirectory: () => true } );
stubs.fs.statSync.withArgs( '/home/project/external/bar' ).returns( { isDirectory: () => true } );
stubs.tools.getDirectories.withArgs( '/home/project/packages' ).returns( [
'ckeditor5-core',
'ckeditor5-engine'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const path = require( 'path' );
const fs = require( 'fs-extra' );
const { CKEditorTranslationsPlugin } = require( '@ckeditor/ckeditor5-dev-translations' );
const bundler = require( '../bundler' );
const tools = require( '../tools' );
const loaders = require( '../loaders' );

/**
Expand All @@ -33,7 +32,7 @@ module.exports = function getDllPluginWebpackConfig( webpack, options ) {
// See: https://github.com/ckeditor/ckeditor5/issues/13136.
const TerserPlugin = require( 'terser-webpack-plugin' );

const packageName = tools.readPackageName( options.packagePath );
const { name: packageName } = require( path.join( options.packagePath, 'package.json' ) );
const langDirExists = fs.existsSync( path.join( options.packagePath, 'lang' ) );
const indexJsExists = fs.existsSync( path.join( options.packagePath, 'src', 'index.js' ) );

Expand Down
Loading

0 comments on commit 7739dd0

Please sign in to comment.