https://pulumi.com logo
#general
Title
# general
e

elegant-crayon-4967

03/13/2020, 8:18 PM
got an easy one…today I’m focusing on unit testing following the post here https://www.pulumi.com/blog/unit-testing-infrastructure-in-nodejs-and-mocha/ Although my linter complains about moving the following functions
Copy code
// runTests executes all test files (*.ts) in the current directory.
export function runTests() {
    // Create a new Mocha test runner (with a long timeout).
    const mocha = new Mocha({ timeout: 1000*60*30 });

    // Only keep the .ts files, and skip this file (index.ts).
    const testDir = __dirname;
    fs.readdirSync(testDir).
        filter(file => file.endsWith(".ts") && file !== "index.ts").
            forEach(file => { mocha.addFile(path.join(testDir, file)); });

    // Now actually run the tests with the desired reporter.
    console.log(`Running Mocha Tests: ${mocha.files}`);
    mocha.reporter("spec").run(failures => {
        process.exitCode = failures ? 1 : 0;
    });
}

// promise returns a resource output's value, even if it's undefined.
export function promise<T>(output: pulumi.Output<T>): Promise<T | undefined> {
    return (output as any).promise() as Promise<T>;
}
to arrow functions. I’m not sure how to do that for the
export function promise<T>
anyone have updated code that uses arrow functions for the testing?
responding to my own ask…I think the following works
Copy code
export const promise: <T>(output: pulumi.Output<T>) => 
  pulumi.Output<T> = (output) => output;