<commit_before>'use strict';

const path = require('path');
const fs = require('fs-extra');

const runCommand = require('../helpers/run-command');
const acceptance = require('../helpers/acceptance');
const DistChecker = require('../helpers/dist-checker');
const copyFixtureFiles = require('../helpers/copy-fixture-files');
let createTestTargets = acceptance.createTestTargets;
let teardownTestTargets = acceptance.teardownTestTargets;
let linkDependencies = acceptance.linkDependencies;
let cleanupRun = acceptance.cleanupRun;

const chai = require('../chai');
let expect = chai.expect;
let dir = chai.dir;

let appName = 'some-cool-app';
let appRoot;

describe('Acceptance: preprocessor-smoke-test', function () {
  this.timeout(360000);

  before(function () {
    return createTestTargets(appName);
  });

  after(teardownTestTargets);

  beforeEach(function () {
    appRoot = linkDependencies(appName);
  });

  afterEach(function () {
    runCommand.killAll();
    cleanupRun(appName);
    expect(dir(appRoot)).to.not.exist;
  });

  it('addons with standard preprocessors compile correctly', async function () {
    await copyFixtureFiles(`preprocessor-tests/app-with-addon-with-preprocessors`);

    let packageJsonPath = path.join(appRoot, 'package.json');
    let packageJson = fs.readJsonSync(packageJsonPath);
    packageJson.devDependencies['ember-cli-sass'] = 'latest';
    packageJson.devDependencies['ember-cool-addon'] = 'latest';
    fs.writeJsonSync(packageJsonPath, packageJson);

    await runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');

    let checker = new DistChecker(path.join(appRoot, 'dist'));

    expect(checker.contains('css', 'app styles included')).to.be;
    expect(checker.contains('css', 'addon styles included')).to.be;
  });

  it('addon registry entries are added in the proper order', async function () {
    await copyFixtureFiles(`preprocessor-tests/app-registry-ordering`);

    let packageJsonPath = path.join(appRoot, 'package.json');
    let packageJson = fs.readJsonSync(packageJsonPath);
    packageJson.devDependencies['first-dummy-preprocessor'] = 'latest';
    packageJson.devDependencies['second-dummy-preprocessor'] = 'latest';
    fs.writeJsonSync(packageJsonPath, packageJson);

    await runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');

    let checker = new DistChecker(path.join(appRoot, 'dist'));

    expect(checker.contains('js', 'replacedByPreprocessor'), 'token should have been replaced in app bundle').to.be;
    expect(checker.contains('js', '__SECOND_PREPROCESSOR_REPLACEMENT_TOKEN__'), 'token should not be contained').to.not
      .be;
    expect(checker.contains('js', '__FIRST_PREPROCESSOR_REPLACEMENT_TOKEN__'), 'token should not be contained').to.not
      .be;
  });

  it('addons without preprocessors compile correctly', async function () {
    await copyFixtureFiles(`preprocessor-tests/app-with-addon-without-preprocessors`);

    let packageJsonPath = path.join(appRoot, 'package.json');
    let packageJson = fs.readJsonSync(packageJsonPath);
    packageJson.devDependencies['ember-cli-sass'] = 'latest';
    packageJson.devDependencies['ember-cool-addon'] = 'latest';
    fs.writeJsonSync(packageJsonPath, packageJson);

    await runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');

    let checker = new DistChecker(path.join(appRoot, 'dist'));

    expect(checker.contains('css', 'app styles included')).to.be;
    expect(checker.contains('css', 'addon styles included')).to.be;
  });

  /*
    [ app ]  -> [ addon ] -> [ preprocessor addon ]
      |             |
      |             |--- preprocessor applies to this
      |
      |-- preprocessor should not apply to this
  */
  it('addons depending on preprocessor addon preprocesses addon but not app', async function () {
    await copyFixtureFiles(`preprocessor-tests/app-with-addon-with-preprocessors-2`);

    let packageJsonPath = path.join(appRoot, 'package.json');
    let packageJson = fs.readJsonSync(packageJsonPath);
    packageJson.devDependencies['ember-cool-addon'] = 'latest';
    fs.writeJsonSync(packageJsonPath, packageJson);

    await runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');

    let checker = new DistChecker(path.join(appRoot, 'dist'));

    expect(
      checker.contains('js', 'foo_in_app: __PREPROCESSOR_REPLACEMENT_TOKEN__'),
      'token should not have been replaced in app bundle'
    ).to.be;
    expect(
      checker.contains('js', 'foo_in_app: "replacedByPreprocessor"'),
      'token should not have been replaced in app bundle'
    ).to.not.be;

    expect(
      checker.contains('js', 'foo_in_addon: "replacedByPreprocessor"'),
      'token should have been replaced in vendor bundle'
    ).to.be;
    expect(
      checker.contains('js', 'foo_in_addon: __PREPROCESSOR_REPLACEMENT_TOKEN__'),
      'token should have been replaced in vendor bundle'
    ).to.not.be;
  });

  /*
    [ app ]  -> [ addon ] ->  [ addon ] -> [ preprocessor addon ]
      |             |             |
      |             |             |--- preprocessor applies to this
      |             |
      |             |-- preprocessor should not apply to this
      |
      |-- preprocessor should not apply to this
  */
  it('addon N levels deep depending on preprocessor preprocesses that parent addon only', async function () {
    await copyFixtureFiles(`preprocessor-tests/app-with-addon-with-preprocessors-3`);

    let packageJsonPath = path.join(appRoot, 'package.json');
    let packageJson = fs.readJsonSync(packageJsonPath);
    packageJson.devDependencies['ember-shallow-addon'] = 'latest';

    fs.writeJsonSync(packageJsonPath, packageJson);

    await runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');

    let checker = new DistChecker(path.join(appRoot, 'dist'));

    expect(
      checker.contains('js', 'foo_in_app: __PREPROCESSOR_REPLACEMENT_TOKEN__'),
      'token should not have been replaced in app bundle'
    ).to.be;
    expect(
      checker.contains('js', 'foo_in_app: "replacedByPreprocessor"'),
      'token should not have been replaced in app bundle'
    ).to.not.be;

    expect(
      checker.contains('js', 'deep: "replacedByPreprocessor"'),
      'token should have been replaced in deep component'
    ).to.be;<commit_msg>skip embroider until embroider is released<commit_after>'use strict';

const path = require('path');
const fs = require('fs-extra');

const runCommand = require('../helpers/run-command');
const acceptance = require('../helpers/acceptance');
const DistChecker = require('../helpers/dist-checker');
const copyFixtureFiles = require('../helpers/copy-fixture-files');
const { isExperimentEnabled } = require('../../lib/experiments');
let createTestTargets = acceptance.createTestTargets;
let teardownTestTargets = acceptance.teardownTestTargets;
let linkDependencies = acceptance.linkDependencies;
let cleanupRun = acceptance.cleanupRun;

const chai = require('../chai');
let expect = chai.expect;
let dir = chai.dir;

let appName = 'some-cool-app';
let appRoot;

describe('Acceptance: preprocessor-smoke-test', function () {
  this.timeout(360000);

  before(function () {
    return createTestTargets(appName);
  });

  after(teardownTestTargets);

  beforeEach(function () {
    appRoot = linkDependencies(appName);
  });

  afterEach(function () {
    runCommand.killAll();
    cleanupRun(appName);
    expect(dir(appRoot)).to.not.exist;
  });

  it('addons with standard preprocessors compile correctly', async function () {
    if (isExperimentEnabled('EMBROIDER')) {
      return this.skip();
    }
    await copyFixtureFiles(`preprocessor-tests/app-with-addon-with-preprocessors`);

    let packageJsonPath = path.join(appRoot, 'package.json');
    let packageJson = fs.readJsonSync(packageJsonPath);
    packageJson.devDependencies['ember-cli-sass'] = 'latest';
    packageJson.devDependencies['ember-cool-addon'] = 'latest';
    fs.writeJsonSync(packageJsonPath, packageJson);

    await runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');

    let checker = new DistChecker(path.join(appRoot, 'dist'));

    expect(checker.contains('css', 'app styles included')).to.be;
    expect(checker.contains('css', 'addon styles included')).to.be;
  });

  it('addon registry entries are added in the proper order', async function () {
    if (isExperimentEnabled('EMBROIDER')) {
      return this.skip();
    }
    await copyFixtureFiles(`preprocessor-tests/app-registry-ordering`);

    let packageJsonPath = path.join(appRoot, 'package.json');
    let packageJson = fs.readJsonSync(packageJsonPath);
    packageJson.devDependencies['first-dummy-preprocessor'] = 'latest';
    packageJson.devDependencies['second-dummy-preprocessor'] = 'latest';
    fs.writeJsonSync(packageJsonPath, packageJson);

    await runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');

    let checker = new DistChecker(path.join(appRoot, 'dist'));

    expect(checker.contains('js', 'replacedByPreprocessor'), 'token should have been replaced in app bundle').to.be;
    expect(checker.contains('js', '__SECOND_PREPROCESSOR_REPLACEMENT_TOKEN__'), 'token should not be contained').to.not
      .be;
    expect(checker.contains('js', '__FIRST_PREPROCESSOR_REPLACEMENT_TOKEN__'), 'token should not be contained').to.not
      .be;
  });

  it('addons without preprocessors compile correctly', async function () {
    if (isExperimentEnabled('EMBROIDER')) {
      return this.skip();
    }
    await copyFixtureFiles(`preprocessor-tests/app-with-addon-without-preprocessors`);

    let packageJsonPath = path.join(appRoot, 'package.json');
    let packageJson = fs.readJsonSync(packageJsonPath);
    packageJson.devDependencies['ember-cli-sass'] = 'latest';
    packageJson.devDependencies['ember-cool-addon'] = 'latest';
    fs.writeJsonSync(packageJsonPath, packageJson);

    await runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');

    let checker = new DistChecker(path.join(appRoot, 'dist'));

    expect(checker.contains('css', 'app styles included')).to.be;
    expect(checker.contains('css', 'addon styles included')).to.be;
  });

  /*
    [ app ]  -> [ addon ] -> [ preprocessor addon ]
      |             |
      |             |--- preprocessor applies to this
      |
      |-- preprocessor should not apply to this
  */
  it('addons depending on preprocessor addon preprocesses addon but not app', async function () {
    if (isExperimentEnabled('EMBROIDER')) {
      return this.skip();
    }
    await copyFixtureFiles(`preprocessor-tests/app-with-addon-with-preprocessors-2`);

    let packageJsonPath = path.join(appRoot, 'package.json');
    let packageJson = fs.readJsonSync(packageJsonPath);
    packageJson.devDependencies['ember-cool-addon'] = 'latest';
    fs.writeJsonSync(packageJsonPath, packageJson);

    await runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');

    let checker = new DistChecker(path.join(appRoot, 'dist'));

    expect(
      checker.contains('js', 'foo_in_app: __PREPROCESSOR_REPLACEMENT_TOKEN__'),
      'token should not have been replaced in app bundle'
    ).to.be;
    expect(
      checker.contains('js', 'foo_in_app: "replacedByPreprocessor"'),
      'token should not have been replaced in app bundle'
    ).to.not.be;

    expect(
      checker.contains('js', 'foo_in_addon: "replacedByPreprocessor"'),
      'token should have been replaced in vendor bundle'
    ).to.be;
    expect(
      checker.contains('js', 'foo_in_addon: __PREPROCESSOR_REPLACEMENT_TOKEN__'),
      'token should have been replaced in vendor bundle'
    ).to.not.be;
  });

  /*
    [ app ]  -> [ addon ] ->  [ addon ] -> [ preprocessor addon ]
      |             |             |
      |             |             |--- preprocessor applies to this
      |             |
      |             |-- preprocessor should not apply to this
      |
      |-- preprocessor should not apply to this
  */
  it('addon N levels deep depending on preprocessor preprocesses that parent addon only', async function () {
    if (isExperimentEnabled('EMBROIDER')) {
      return this.skip();
    }
    await copyFixtureFiles(`preprocessor-tests/app-with-addon-with-preprocessors-3`);

    let packageJsonPath = path.join(appRoot, 'package.json');
    let packageJson = fs.readJsonSync(packageJsonPath);
    packageJson.devDependencies['ember-shallow-addon'] = 'latest';

    fs.writeJsonSync(packageJsonPath, packageJson);

    await runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');

    let checker = new DistChecker(path.join(appRoot, 'dist'));

    expect(
      checker.contains('js', 'foo_in_app: __PREPROCESSOR_REPLACEMENT_TOKEN__'),
      'token should not have been replaced in app bundle'
    ).to.be;
    expect(
      checker.contains('js', 'foo_in_app: "replacedByPreprocessor"'),
      'token should not have been replaced in app bundle'
    ).to.not.be;

    expect(
      checker.contains('js', 'deep: "replacedByPreprocessor"'),
      'token should have been replaced in deep component'
    ).to.be;
{'fraction_non_alphanumeric': 0.14328876803383941, 'fraction_numerical': 0.0012085504947503588, 'mean_word_length': 3.7971014492753623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7480324', 'n_tokens_mistral': 4081, 'n_tokens_neox': 4024, 'n_words': 859}