<commit_before>'use strict';

const path = require('path');

const Rx = require('rx');
const Test262Stream = require('test262-stream');
const minimatch = require('minimatch');

// test262-harness accepts file names and patterns as input; test262-stream
// accepts file names and directory names. To accomodate this, file patterns
// containing globs are truncated to the most precise directory name. All files
// within this directory are visited by test262-stream, but only those tests
// which match the pattern are emitted to from this module.
function patternsToDirectories(patterns) {
  return patterns.map((pattern) => {
    const parts = [];

    pattern.split(path.sep).every((part) => {
      if (part.indexOf('*') > -1 || part.slice(-3).toLowerCase() === '.js') {
        return false;
      }

      parts.push(part);

      return true;
    });

    return parts.join(path.sep);
  }).filter((name) => name !== '');
}

module.exports = function(test262Dir, includesDir, acceptVersion, globPatterns) {
  const paths = patternsToDirectories(globPatterns);
  const stream = new Test262Stream(test262Dir, {
    includesDir, paths, acceptVersion
  });
  const subject = new Rx.Subject();

  stream.on('data', (test) => {
    if (!globPatterns.some((pattern) => minimatch(test.file, pattern))) {
      return;
    }

    // The file paths emitted by test262-stream are relative to the provided
    // Test262 directory. To ensure backwards compatability, they must be
    // modified to be in terms of the current working directory.
    test.file = path.relative(process.cwd(), path.join(test262Dir, test.file));

    subject.onNext(test);
  });
  stream.on('error', (error) => subject.onError(error));
  stream.on('end', () => subject.onCompleted());

  return subject;
};<commit_msg>Add relative path for each test file<commit_after>'use strict';

const path = require('path');

const Rx = require('rx');
const Test262Stream = require('test262-stream');
const minimatch = require('minimatch');

// test262-harness accepts file names and patterns as input; test262-stream
// accepts file names and directory names. To accomodate this, file patterns
// containing globs are truncated to the most precise directory name. All files
// within this directory are visited by test262-stream, but only those tests
// which match the pattern are emitted to from this module.
function patternsToDirectories(patterns) {
  return patterns.map((pattern) => {
    const parts = [];

    pattern.split(path.sep).every((part) => {
      if (part.indexOf('*') > -1 || part.slice(-3).toLowerCase() === '.js') {
        return false;
      }

      parts.push(part);

      return true;
    });

    return parts.join(path.sep);
  }).filter((name) => name !== '');
}

module.exports = function(test262Dir, includesDir, acceptVersion, globPatterns) {
  const paths = patternsToDirectories(globPatterns);
  const stream = new Test262Stream(test262Dir, {
    includesDir, paths, acceptVersion
  });
  const subject = new Rx.Subject();

  stream.on('data', (test) => {
    if (!globPatterns.some((pattern) => minimatch(test.file, pattern))) {
      return;
    }

    // Preserve the relative file path from Test262, ignore the initial test/
    // folder.
    test.path = path.relative('test', test.file);

    // The file paths emitted by test262-stream are relative to the provided
    // Test262 directory. To ensure backwards compatability, they must be
    // modified to be in terms of the current working directory.
    test.file = path.relative(process.cwd(), path.join(test262Dir, test.file));

    subject.onNext(test);
  });
  stream.on('error', (error) => subject.onError(error));
  stream.on('end', () => subject.onCompleted());

  return subject;
};
{'fraction_non_alphanumeric': 0.13690952762209768, 'fraction_numerical': 0.01948225246864158, 'mean_word_length': 3.679151061173533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3664764', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1049, 'n_words': 333}