I've built a Cypress test automation framework with TypeScript.
I have a utility method that gets secrets from Azure key vault. This methods works during the set-up phase, but not when used in a test file/invoked from a test.
Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat 'C:\dev\Automation\automated-testing-service\cypress\configurations\fs' required by C:\dev\Automation\automated-testing-service\node_modules@azure\identity\dist\index.js
I can't seem to debug this when Cypress is running in order to examine the code path/code that will help me understand where it's going wrong, so hereon out I'll be working through the error literally and hopefully logically...
The error message is correct, there is no such file/directory of 'C:\dev\Automation\automated-testing-service\cypress\configurations\fs', but nowhere in my code am I explicitly referencing it.
C:\dev\Automation\automated-testing-service\cypress\configurations\ does happen to be where I'm storing my Cypress configuration files. One per environment...
...but these files should be an irrelevance to getting secrets from the key vault. None of their contents is relied upon to get secrets from the key vault.
Regarding the 'fs' in 'C:\dev\Automation\automated-testing-service\cypress\configurations\fs', I've checked for references to 'fs' in 'C:\dev\Automation\automated-testing-service\node_modules@azure\identity\dist\index.js' and found:
var fs = require('fs');
var promises = require('fs/promises');
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
/**
* Retrieves the file contents at the given path using promises.
* Useful since `fs`'s readFileSync locks the thread, and to avoid extra dependencies.
*/
function readFileAsync$1(path, options) {
return new Promise((resolve, reject) => fs.readFile(path, options, (err, data) => {
if (err) {
reject(err);
}
resolve(data);
}));
}
The above is not the contents of the entire file, just what I believe are possible pertinent snippets.
Perhaps the above is/are a red herring(s), so let's compare what I'm doing between what works and what doesn't.
Approach that works:
I run a script in the command prompt:
npm run data.refresh.qa
which in-turn runs:
ts-node cypress/initiator.ts --refreshTestData --environment=qa
initiator.ts, amongst other unrelated things, calls the following method in my utility file (test-data-utilities.ts):
export async function getSecretFromAzureKeyVault(secretToAcquire: string, environment: string) {
const credential = new DefaultAzureCredential();
const url = `https://kv-${environment}-censored.vault.azure.net`;
const client = new SecretClient(url, credential);
const secret = await client.getSecret(secretToAcquire);
return secret.value;
}
The call(s) to this method that are successful are the ones where I'm getting the database username and password from the vault to perform test data teardown/setup.
Once the set-up phase is done, initiator.ts executes the following command to start the test run:
execSync(`npx cypress run --config-file cypress/configurations/${argv.environment}-config.ts`, {stdio: 'inherit'});
Approach that doesn't work:
After 'Approach that works' starts the test run, and assuming my test file is...
import { getSecretFromAzureKeyVault } from '../../support/test_data/utilities/test-data-utilities';
describe('Access Controller API Tests', () => {
it('some test', async() => {
const mySecret = await getSecretFromAzureKeyVault('get-my-secret', 'qa');
});
}
...and I'm like...
...there should be no graph to walk...
Thank you for any help you may be able to provide.
I discovered on https://github.com/aws/aws-sdk-js-v3/issues/5349 that the cypress-tags plugin is causing the issue. I uninstalled cypress-tags v1.2.2 and the above error no longer occurs.