Skip to content

Commit

Permalink
use spawn instead, #384
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 12, 2024
1 parent a69404f commit 3b92b5d
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions js/test/test-exec-sync.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
// Copyright 2024, University of Colorado Boulder

/**
* Test that we can invoke a grunt task from the command line, and make sure the options are passed correctly.
* Test that we can invoke a task from the command line, and make sure the options are passed correctly.
*
* @author Sam Reid (PhET Interactive Simulations)
* @author Michael Kauzmann (PhET Interactive Simulations)
*/

import { execSync } from 'child_process';
import { spawnSync } from 'child_process';
import fs from 'fs';
import _ from 'lodash';
import qunit from 'qunit';
import gruntCommand from '../common/gruntCommand.js';
import tsxCommand from '../common/tsxCommand.js';

const SIM = 'acid-base-solutions';

const EXEC_SYNC_OPTIONS = {
encoding: 'utf-8'
const SPAWN_SYNC_OPTIONS = {
encoding: 'utf-8',
shell: true
} as const;

const EXEC_AND_SIM_OPTIONS = _.assignIn( {
const SPAWN_FOR_SIM_OPTIONS = _.assignIn( {
cwd: `../${SIM}`
}, EXEC_SYNC_OPTIONS );
}, SPAWN_SYNC_OPTIONS );

qunit.module( 'test-exec-sync' );

const checkOutput = ( result: string, assert: Assert ) => {
assert.ok( result.includes( `<output>
const checkOutput = ( result: ReturnType<typeof spawnSync>, assert: Assert ) => {
assert.ok( result.status === 0 );
assert.ok( result.stdout.includes( `<output>
brands: a,b,c
lint: false
noTSC: true
Expand All @@ -35,27 +38,27 @@ omitted: undefined
};

qunit.test( 'grunt no args', ( assert: Assert ) => {
const result = execSync( `${gruntCommand} test-grunt`, EXEC_SYNC_OPTIONS );
assert.ok( result.match( /: undefined/g )?.length === 4, 'no args, all undefined' );
const result = spawnSync( `${gruntCommand} test-grunt`, SPAWN_SYNC_OPTIONS );
assert.ok( result.stdout.match( /: undefined/g )?.length === 4, 'no args, all undefined' );
} );

qunit.test( 'grunt args', ( assert: Assert ) => {
const result = execSync( `${gruntCommand} test-grunt --brands=a,b,c --lint=false --noTSC`, EXEC_SYNC_OPTIONS );
const result = spawnSync( `${gruntCommand} test-grunt --brands=a,b,c --lint=false --noTSC`, SPAWN_SYNC_OPTIONS );
checkOutput( result, assert );
} );

qunit.test( 'tsx', assert => {
const result = execSync( `${tsxCommand} ../perennial-alias/js/grunt/tasks/test-grunt.ts --brands=a,b,c --lint=false --noTSC`, EXEC_SYNC_OPTIONS );
const result = spawnSync( `${tsxCommand} ./js/grunt/tasks/test-grunt.ts --brands=a,b,c --lint=false --noTSC`, SPAWN_SYNC_OPTIONS );
checkOutput( result, assert );
} );

qunit.test( 'sage run', assert => {
const result = execSync( 'bash ../perennial-alias/bin/sage run ../perennial-alias/js/grunt/tasks/test-grunt.ts --brands=a,b,c --lint=false --noTSC', EXEC_SYNC_OPTIONS );
const result = spawnSync( 'bash ./bin/sage run ./js/grunt/tasks/test-grunt.ts --brands=a,b,c --lint=false --noTSC', SPAWN_SYNC_OPTIONS );
checkOutput( result, assert );
} );

// Sim-specific
qunit.test( `grunt ${SIM}`, ( assert: Assert ) => {
const result = execSync( `${gruntCommand} --brands=a,b,c --lint=false --noTSC --test-options`, EXEC_AND_SIM_OPTIONS );
const result = spawnSync( `${gruntCommand} --brands=a,b,c --lint=false --noTSC --test-options`, SPAWN_FOR_SIM_OPTIONS );
checkOutput( result, assert );
} );

0 comments on commit 3b92b5d

Please sign in to comment.