java-james / flutter_dotenv

Loads environment variables from `.env`.
https://pub.dartlang.org/packages/flutter_dotenv
MIT License
209 stars 46 forks source link

Issues using testLoad() in integration tests #63

Closed n-doton closed 1 year ago

n-doton commented 1 year ago

I'm trying to read env variables in an integration test. I've successfully read the .env file in my main.dart file using await dotenv.load(fileName: ".env");, but attempting to use the testLoad() function in an integration test returns OS Error: No such file or directory, errno = 2.

I've added the .env file path to assets section of the pubspec.yaml. The file is located at root level, so I'm attempting to read the file in the integration test using dotenv.testLoad(fileInput: File('.env').readAsStringSync());. I've also attempted moving the .env file to the root of my integration_test/ directory, which results in the same error mentioned above.

Is there anything I'm missing here? I don't get an error when reading the .env file in my integration test using await dotenv.load(fileName: ".env");, but any attempt to log the variables within the file returns null.

Thanks in advance.

ymerdrengene commented 1 year ago

@n-doton did you find a solution for this?

n-doton commented 1 year ago

@ymerdrengene We managed to solve this issue by initialising DotEnv in the test this way:

final env = DotEnv(includePlatformEnvironment: true)
      ..load();