Skip to content

Conversation

shahzad31
Copy link
Contributor

@shahzad31 shahzad31 commented Mar 3, 2025

fixes #897 !!

Will allow user to import files as part of journey

Question

Should we handle this outside of files added via journey file?
or we should force user to explictely import files using import syntax? like import './data.csv';

example

import { journey, step, expect } from '@elastic/synthetics';
import * as fs from 'node:fs';
import path from 'path';
import './data.csv';

const csvPath = path.join(__dirname, 'data.csv');

function readCSV(filePath: string): string[] {
  const data = fs.readFileSync(filePath, 'utf8');
  return data.split('\n').map(line => line.trim()); // Split by line & trim spaces
}

journey('CSV Content Verification', async ({ page }) => {
  step('Read CSV file and verify content', async () => {
    // Read the CSV file
    const rows = readCSV(csvPath);

    console.log('CSV Content:', rows);

    // Check if it contains expected headers
    expect(rows[0]).toBe('id,name,age');

    // Check if a specific record exists
    expect(rows).toContain('2,Bob,25'); // Verify Bob's entry exists
  });
});

content of file data.csv file

id,name,age
1,Alice,30
2,Bob,25
3,Charlie,35

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

Successfully merging this pull request may close these issues.

Unable to push a xlsx file to use in test
1 participant