Skip to content

Commit

Permalink
Updated e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkenchugonde committed Mar 9, 2024
1 parent d4841c1 commit 9b3939d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 52 deletions.
12 changes: 6 additions & 6 deletions e2e/__tests__/__snapshots__/listTests.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`causes tests to be printed in different lines 1`] = `
exports[`--listTests flag causes tests to be printed out as JSON when using the --json flag 1`] = `"["/MOCK_ABSOLUTE_PATH/e2e/list-tests/__tests__/dummy.test.js","/MOCK_ABSOLUTE_PATH/e2e/list-tests/__tests__/other.test.js"]"`;

exports[`--outputFile flag causes tests to be saved in the file as JSON 1`] = `"["/MOCK_ABSOLUTE_PATH/e2e/list-tests/__tests__/dummy.test.js","/MOCK_ABSOLUTE_PATH/e2e/list-tests/__tests__/other.test.js"]"`;

exports[`--outputFile flag causes tests to be saved in the file in different lines 1`] = `
"/MOCK_ABSOLUTE_PATH/e2e/list-tests/__tests__/dummy.test.js
/MOCK_ABSOLUTE_PATH/e2e/list-tests/__tests__/other.test.js"
`;

exports[`causes tests to be printed out as JSON when using the --json flag 1`] = `"["/MOCK_ABSOLUTE_PATH/e2e/list-tests/__tests__/dummy.test.js","/MOCK_ABSOLUTE_PATH/e2e/list-tests/__tests__/other.test.js"]"`;

exports[`causes tests to be saved in the file as JSON 1`] = `"["/MOCK_ABSOLUTE_PATH/e2e/list-tests/__tests__/dummy.test.js","/MOCK_ABSOLUTE_PATH/e2e/list-tests/__tests__/other.test.js"]"`;

exports[`causes tests to be saved in the file in different lines 1`] = `
exports[`causes tests to be printed in different lines 1`] = `
"/MOCK_ABSOLUTE_PATH/e2e/list-tests/__tests__/dummy.test.js
/MOCK_ABSOLUTE_PATH/e2e/list-tests/__tests__/other.test.js"
`;
90 changes: 44 additions & 46 deletions e2e/__tests__/listTests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ const normalizePaths = (rawPaths: string) =>
.split('\\')
.join('/');

const outputFilePath = path.resolve('.', 'test-lists.json');

describe('--listTests flag', () => {
afterAll(() => {
fs.unlinkSync(outputFilePath);
});
it('causes tests to be printed in different lines', () => {
const {exitCode, stdout} = runJest('list-tests', ['--listTests']);

Expand All @@ -29,7 +34,7 @@ describe('--listTests flag', () => {
).toMatchSnapshot();
});

it('causes tests to be printed out as JSON when using the --json flag', () => {
it('--listTests flag causes tests to be printed out as JSON when using the --json flag', () => {
const {exitCode, stdout} = runJest('list-tests', ['--listTests', '--json']);

expect(exitCode).toBe(0);
Expand All @@ -39,50 +44,43 @@ describe('--listTests flag', () => {
).toMatchSnapshot();
});

describe('--outputFile flag', () => {
const outputFilePath = path.resolve('.', 'test-lists.json');
afterAll(() => {
fs.unlinkSync(outputFilePath);
});
it('causes tests to be saved in the file as JSON', () => {
const {exitCode, stdout} = runJest('list-tests', [
'--listTests',
'--json',
'--outputFile',
outputFilePath,
]);

expect(exitCode).toBe(0);
expect(stdout).toBe('');

const outputFileExists = fs.existsSync(outputFilePath);
expect(outputFileExists).toBe(true);

const outputFileContent = fs.readFileSync(outputFilePath, 'utf8');
expect(() => JSON.parse(outputFileContent)).not.toThrow();
expect(
JSON.stringify(
JSON.parse(outputFileContent).map(normalizePaths).sort(),
),
).toMatchSnapshot();
});
it('causes tests to be saved in the file in different lines', () => {
const {exitCode, stdout} = runJest('list-tests', [
'--listTests',
'--outputFile',
outputFilePath,
]);

expect(exitCode).toBe(0);
expect(stdout).toBe('');

const outputFileExists = fs.existsSync(outputFilePath);
expect(outputFileExists).toBe(true);

const outputFileContent = fs.readFileSync(outputFilePath, 'utf8');
expect(
normalizePaths(outputFileContent).split('\n').sort().join('\n'),
).toMatchSnapshot();
});
it('--outputFile flag causes tests to be saved in the file as JSON', () => {
const {exitCode, stdout} = runJest('list-tests', [
'--listTests',
'--json',
'--outputFile',
outputFilePath,
]);

expect(exitCode).toBe(0);
expect(stdout).toBe('');

const outputFileExists = fs.existsSync(outputFilePath);
expect(outputFileExists).toBe(true);

const outputFileContent = fs.readFileSync(outputFilePath, 'utf8');
expect(() => JSON.parse(outputFileContent)).not.toThrow();
expect(
JSON.stringify(JSON.parse(outputFileContent).map(normalizePaths).sort()),
).toMatchSnapshot();
});

it('--outputFile flag causes tests to be saved in the file in different lines', () => {
const {exitCode, stdout} = runJest('list-tests', [
'--listTests',
'--outputFile',
outputFilePath,
]);

expect(exitCode).toBe(0);
expect(stdout).toBe('');

const outputFileExists = fs.existsSync(outputFilePath);
expect(outputFileExists).toBe(true);

const outputFileContent = fs.readFileSync(outputFilePath, 'utf8');
expect(
normalizePaths(outputFileContent).split('\n').sort().join('\n'),
).toMatchSnapshot();
});
});

0 comments on commit 9b3939d

Please sign in to comment.