Skip to content

Commit

Permalink
Change test:all to clean up each example after running it (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
tudorpavel authored and GantMan committed Oct 19, 2019
1 parent 59f5195 commit 34e5d8c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 91 deletions.
51 changes: 9 additions & 42 deletions test/modules_test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
const bluebird = require( 'bluebird' );

const {

getDirectories,

constants: {

TEMPORARY_TEST_FILES
}

} = require( '../utils' );
} = require( '../utils' );

const testReactDirectory = require( './test_react_directory' );

Expand All @@ -25,11 +25,6 @@ describe( 'Modules Test', function() {

this.timeout( Infinity );

before( function() {

return removeTemporaryTestFiles();
});

[
{
title: 'Each React module passes test',
Expand Down Expand Up @@ -60,9 +55,9 @@ describe( 'Modules Test', function() {
it( title, function() {

return getDirectories({

path: pathForLibraries

}).then( directories => {

// NOTE: used to run test on single directory
Expand All @@ -78,25 +73,25 @@ describe( 'Modules Test', function() {
}).then( testResults => {

console.log(

'Results:',

JSON.stringify( testResults, null, 4 )
);

const errorDirectories = testResults.filter(

result => !!result.error

).map(

errorResult => errorResult.directory
);

if( errorDirectories.length > 0 ) {

throw new Error(

`${ pathForLibraries } libraries that ` +
`failed the test: ` +
JSON.stringify( errorDirectories )
Expand All @@ -106,31 +101,3 @@ describe( 'Modules Test', function() {
});
});
});


// helper functions
function removeTemporaryTestFiles() {

console.log( 'removing existing temporary test files' );

return execa(

'rm',

[
'-rf',
TEMPORARY_TEST_FILES,
],

{
cwd: `${ process.cwd() }/test`
}

).then( () => {

console.log(

'successfully removed existing temporary test files'
);
});
}
46 changes: 25 additions & 21 deletions test/modules_test/test_react_directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@
/* jshint expr: true */

const {


makeDirectoryCleanupFunction,

constants: {

TEMPORARY_TEST_FILES
}

} = require( '../utils' );
} = require( '../utils' );

const execa = require( 'execa' );


module.exports = ({ directory }) => {

const testDirectory = (

`test/${ TEMPORARY_TEST_FILES }/React/${ directory }/`
);

const fullTestDirectoryPath = `${ process.cwd() }/${ testDirectory }`;

let stage = 'start';

const finallyRemoveTemporaryDirectory = makeDirectoryCleanupFunction(testDirectory);

return execa(

'mkdir',

[
Expand All @@ -38,32 +42,32 @@ module.exports = ({ directory }) => {
stage = 'copy';

return execa(

'cp',

[
'-a',
`React/${ directory }/.`,
testDirectory,
]
);

}).then( () => {

stage = 'yarn';

console.log( `running yarn in ${ testDirectory }` );

return execa(

'yarn',

[],

{
cwd: fullTestDirectoryPath
}
);
);

}).then( () => {

Expand All @@ -72,7 +76,7 @@ module.exports = ({ directory }) => {
console.log( `running yarn build in ${ testDirectory }` );

return execa(

'yarn',

[
Expand All @@ -82,7 +86,7 @@ module.exports = ({ directory }) => {
{
cwd: fullTestDirectoryPath
}
);
);

}).then( () => {

Expand All @@ -91,8 +95,8 @@ module.exports = ({ directory }) => {
console.log( `running CI=true yarn test in ${ testDirectory }` );

return execa(
'yarn',

'yarn',

[
'test'
Expand All @@ -104,16 +108,16 @@ module.exports = ({ directory }) => {
CI: true
}
}
);
);

}).then( () => {

stage = 'finish';

console.log( `${ directory } passed test` );

return {

directory,
passedTests: true,
// data: result.stdout
Expand All @@ -124,10 +128,10 @@ module.exports = ({ directory }) => {
console.log( `${ directory } failed test at stage: ${ stage }` );

return {

passedTests: false,
directory,
error: err
};
});
};
}).then(finallyRemoveTemporaryDirectory, finallyRemoveTemporaryDirectory);
};
42 changes: 23 additions & 19 deletions test/modules_test/test_react_native_directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@
/* jshint expr: true */

const {


makeDirectoryCleanupFunction,

constants: {

TEMPORARY_TEST_FILES
}

} = require( '../utils' );
} = require( '../utils' );

const execa = require( 'execa' );


module.exports = ({ directory }) => {

const testDirectory = (

`test/${ TEMPORARY_TEST_FILES }/ReactNative/${ directory }/`
);

const fullTestDirectoryPath = `${ process.cwd() }/${ testDirectory }`;

let stage = 'start';

const finallyRemoveTemporaryDirectory = makeDirectoryCleanupFunction(testDirectory);

return execa(

'mkdir',

[
Expand All @@ -38,24 +42,24 @@ module.exports = ({ directory }) => {
stage = 'copy';

return execa(

'cp',

[
'-a',
`ReactNative/${ directory }/.`,
testDirectory,
]
);

}).then( () => {

stage = 'npm install';

console.log( `running npm install in ${ testDirectory }` );

return execa(

'npm',

[
Expand All @@ -66,7 +70,7 @@ module.exports = ({ directory }) => {
cwd: fullTestDirectoryPath
}
);

}).then( () => {

stage = 'ios';
Expand Down Expand Up @@ -95,7 +99,7 @@ module.exports = ({ directory }) => {
{
cwd: fullTestDirectoryPath
}
);
);

}).then( () => {

Expand All @@ -104,7 +108,7 @@ module.exports = ({ directory }) => {
console.log( `running android command in ${ testDirectory }` );

return execa(

'react-native',

[
Expand All @@ -125,16 +129,16 @@ module.exports = ({ directory }) => {
{
cwd: fullTestDirectoryPath
}
);
);

}).then( () => {

stage = 'finish';

console.log( `${ directory } passed test` );

return {

directory,
passedTests: true,
// data: result.stdout
Expand All @@ -145,10 +149,10 @@ module.exports = ({ directory }) => {
console.log( `${ directory } failed test at stage: ${ stage }` );

return {

passedTests: false,
directory,
error: err
};
});
};
}).then(finallyRemoveTemporaryDirectory, finallyRemoveTemporaryDirectory);
};
Loading

0 comments on commit 34e5d8c

Please sign in to comment.