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

How about environment variables insertion or custom cli option processing omitting when app launching? #8269

Open
tomoh1r opened this issue Aug 31, 2024 · 5 comments
Labels
STATE: Need clarification An issue lacks information for further research. TYPE: enhancement The accepted proposal for future implementation.

Comments

@tomoh1r
Copy link

tomoh1r commented Aug 31, 2024

What is your Scenario?

I know TestCafe could treat a configuration file, but I need complex pattern resolvement.

This issue aims to treat environment variables on Windows terminals, macOS/Linux could one liner with ENV=stg testcafe ~, but we need two steps on Windows. The issue resolves this issue.

If I construct custom teardown test process and need to run only this, I'd like to add --cleanup custom argument and it could treat this on cjs configration script.

Or, If I could add --stg or --env=ENV=stg argument, it will run stg testing, and I use --cleanup --stg will clean stg environment.

What are you suggesting?

I need a or b, I think a is easier than b

a. --env argument and modify environment variables

I could set --env ENV=stg,TASK=teardown settings, and I could use this environment variables on Configuration CJS script (.testcaferc.cjs) to switch our test behaving.

I know we (user on Windows) can set environment variables other lines, but it is easier to set values one liner, I need.

b. add feature to set custom user argument omitting setting

I know if add unregistered argument to app launch, it will be cause error to tell "no such test files", I'd like to suppress this error.

If we could set { customArgs: ["--environment", "--cleanup"] } to (.testcaferc.json), I could treat this argument on Configuration CJS script (.testcaferc.cjs) to switch our test behaving.

If customArgs conflics embded arguments, I expect it will cause error.

What alternatives have you considered?

No response

Additional context

No response

@tomoh1r tomoh1r added the TYPE: enhancement The accepted proposal for future implementation. label Aug 31, 2024
@testcafe-need-response-bot testcafe-need-response-bot bot added the STATE: Need response An issue that requires a response or attention from the team. label Aug 31, 2024
@PavelMor25
Copy link
Collaborator

Hello @tomoh1r,

Could you please describe your usage scenario in more detail? Specifically, what aspects depend on your customArgs or environment variables? If possible, please share a minimal example of what your .testcaferc.cjs file might look like.

@PavelMor25 PavelMor25 added STATE: Need clarification An issue lacks information for further research. and removed STATE: Need response An issue that requires a response or attention from the team. labels Sep 5, 2024
@tomoh1r
Copy link
Author

tomoh1r commented Sep 8, 2024

Hi @PavelMor25 , thank you for your response.

your usage scenario in more detail?

I’m looking to manage setup and cleanup cases. Sometimes, test cases need to set up data or finalize unusual data. In this case, I’d like to modify TestCafe’s behavior so that it can either run cleanup only or run cleanup before setup.

It would be great if we could control test case behavior with a simple command. This would give us more flexibility.

what aspects depend on your customArgs or environment variables?

Although we can use test meta to filter, we usually implement tests with both setup and cleanup scenarios. I want to switch the behavior to either run cleanup only or run cleanup before setup. I think test meta doesn’t fit this case because I expect this behavior to be applied within a single test, rather than being decoupled.

If I can set customArgs or environment variables, I can configure these settings in the .testcaferc.cjs file.

If possible, please share a minimal example of what your .testcaferc.cjs file might look like.

Here’s a minimal example of how we might use customArgs to switch behavior with userVariables in the test case. Alternatively, if we use environment variables, we can use process.env instead of userVariables.

const process = require('process');

const args = process.argv.slice(2);
const cleanupOnly = args.includes('--cleanup');
const cleanupOnSetup = args.includes('--cleanup-on-setup');

module.exports = {
  userVariables: {
    cleanupOnly: cleanupOnly,
    cleanupOnSetup: cleanupOnSetup
  }
};

Feel free to ask any questions.

@testcafe-need-response-bot testcafe-need-response-bot bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 8, 2024
@github-actions github-actions bot removed the STATE: Need clarification An issue lacks information for further research. label Sep 8, 2024
@PavelMor25
Copy link
Collaborator

Hello @tomoh1r,

We have received a similar request before: the user wanted to set a project configuration that is unique for every test run by creating a new environment instance before testing. Could you please review the #8195 issue and check if the proposed workaround there can be adapted to your usage scenario?

Please let me know your results.

@PavelMor25 PavelMor25 added STATE: Need clarification An issue lacks information for further research. and removed STATE: Need response An issue that requires a response or attention from the team. labels Sep 11, 2024
@tomoh1r
Copy link
Author

tomoh1r commented Sep 14, 2024

Hi @PavelMor25,

My scenario involves changing test case behavior using custom or environment arguments, regardless of whether the environment is isolated. Therefore, #8195 does not apply to the case in #8269.

The issue proposes creating a new mechanism for altering test behavior. I’m not affected by this problem and believe the focus is on deciding whether or not to implement the mechanism.

The core of my idea is to block and filter test cases. I envision using flags with arguments to conditionally run or skip blocks of code. Here’s an example of what I have in mind:

const { userVariables } = require('testcafe');

test('foo', async (t) => {
  if (!userVariables.cleanupOnly) {
    // setup code
    await someSetup();

    // test case code
    await t.expect(result).ok();
  }

  // cleanup code
  await doCleanup();
});

Feel free to ask any questions.

@testcafe-need-response-bot testcafe-need-response-bot bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 14, 2024
@github-actions github-actions bot removed the STATE: Need clarification An issue lacks information for further research. label Sep 14, 2024
@PavelMor25
Copy link
Collaborator

Hello @tomoh1r ,

Thank you for the explanation.
 

Therefore, #8195 does not apply to the case in #8269.

You can utilize Environment Variables directly in your tests. For more details, please refer to Access Environment Variables in Tests.

Does this approach cover the use case you described?

@PavelMor25 PavelMor25 added STATE: Need clarification An issue lacks information for further research. and removed STATE: Need response An issue that requires a response or attention from the team. labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATE: Need clarification An issue lacks information for further research. TYPE: enhancement The accepted proposal for future implementation.
Projects
None yet
Development

No branches or pull requests

2 participants