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

Output file does not get created when running in a jest test. #37

Closed
luethiandrin opened this issue Nov 29, 2022 · 0 comments
Closed

Output file does not get created when running in a jest test. #37

luethiandrin opened this issue Nov 29, 2022 · 0 comments

Comments

@luethiandrin
Copy link

I am trying to validate the creation and substitution of both template and output file in a jest test.
It works perfectly outside of a jest test --> plain js script. Am I missing out on something or is this a bug?

code(node js):

constant:

module.exports = Object.freeze({
    DEFAULT_ENVIRONMENT_SUBSTITUTION_OPTIONS: {
        all: true,
        diff: true,
        system: true,
        syntax: 'dollar-both', // env pattern: ${} and $
        envs: [{ name: 'release_version' }, { name: 'repo_suffix' }],
    }
});

function:

const substituteEnvForAllFiles = (filePathsArray, options=DEFAULT_ENVIRONMENT_SUBSTITUTION_OPTIONS) => {
    let outputFiles = [];
    filePathsArray.forEach((value) => {
        if (value === '') return;
        const output = value.replaceAll('.template', '');
        envsub({
            templateFile: value,
            outputFile: value.replaceAll('.template', ''),
            options,
        });
        outputFiles.push(output);
    });
    return outputFiles;
};

test:

const customEnvsubstOptions = {
    all: true,
    diff: true,
    system: true,
    syntax: 'dollar-both',
    envs: [{ name: 'test_env' }, { name: 'test_version' }],
};

const templateFilePaths = [
    "<cwd>/.gitlab/node/test/resource/someFileWithEnv-ci.template.yml",
    "<cwd>/.gitlab/node/test/resource/sub-dir/someFileWithEnv-ci.template.yml"
];

const resolvedTemplateFilePaths= [
    "<cwd>/.gitlab/node/test/resource/someFileWithEnv-ci.yml",
    "<cwd>/.gitlab/node/test/resource/sub-dir/someFileWithEnv-ci.yml"
];

it('should substitute all given files and write it out to a new file', () => {
    const outputFiles = substituteEnvForAllFiles(templateFilePaths, customEnvsubstOptions);
    assert.deepEqual(outputFiles, resolvedTemplateFilePaths);
});

files:
The yml files to substitute look like this.

.test-template: &test-template
    image: $test_env/bla/bla/image:$test_version
    tags:
        - test
        - nodejs

Thanks already :)

@luethiandrin luethiandrin closed this as not planned Won't fix, can't repro, duplicate, stale Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant