<commit_before>import path from "path";
import postcss from "postcss";
import rule from "..";

function logError(err) {
  console.log(err.stack); // eslint-disable-line no-console
}

test("No file specified", done => {
  expect.assertions(2);

  postcss([rule()])
    .process("@import 'file.scss';", { from: undefined })
    .then(result => {
      const warnings = result.warnings();
      expect(warnings.length).toBe(1);
      expect(warnings[0].text).toBe(
        "The 'partial-no-import' rule won't work if linting in a code string without an actual file."
      );
      done();
    })
    .catch(logError);
});

test("Import a file from non-partial .scss", done => {
  expect.assertions(1);
  postcss([rule()])
    .process("@import 'file.scss';", {
      from: path.join(__dirname, "test.scss")
    })
    .then(result => {
      const warnings = result.warnings();
      expect(warnings.length).toBe(0);
      done();
    });
});

test("Import a file from a partial .scss", done => {
  expect.assertions(1);
  postcss([rule()])
    .process("@import 'file.scss';", {
      from: path.join(__dirname, "_test.scss")
    })
    .then(result => {
      const warnings = result.warnings();
      expect(warnings.length).toBe(1);
      done();
    });
});

test("Import a file from a partial .scss", done => {
  expect.assertions(1);
  postcss([rule()])
    .process('@import "file.scss";', {
      from: path.join(__dirname, "_test.scss")
    })
    .then(result => {
      const warnings = result.warnings();
      expect(warnings.length).toBe(1);
      done();
    });
});

test("Ignores empty imports (Sass will throw an error instead)", done => {
  expect.assertions(1);
  postcss([rule()])
    .process("@import '';", {
      from: path.join(__dirname, "_test.scss")
    })
    .then(result => {
      const warnings = result.warnings();
      expect(warnings.length).toBe(0);
      done();
    });
});

test("Ignoresd empty imports (Sass will throw an error instead)", done => {
  expect.assertions(1);
  postcss([rule()])
    .process('@import " ";', {
      from: path.join(__dirname, "_test.scss")
    })
    .then(result => {
      const warnings = result.warnings();
      expect(warnings.length).toBe(0);
      done();
    });
});

test("Import a file from a partial .scss; omitting extension", done => {
  expect.assertions(1);
  postcss([rule()])
    .process("@import 'file';", {<commit_msg>fix typo [ci skip]<commit_after>import path from "path";
import postcss from "postcss";
import rule from "..";

function logError(err) {
  console.log(err.stack); // eslint-disable-line no-console
}

test("No file specified", done => {
  expect.assertions(2);

  postcss([rule()])
    .process("@import 'file.scss';", { from: undefined })
    .then(result => {
      const warnings = result.warnings();
      expect(warnings.length).toBe(1);
      expect(warnings[0].text).toBe(
        "The 'partial-no-import' rule won't work if linting in a code string without an actual file."
      );
      done();
    })
    .catch(logError);
});

test("Import a file from non-partial .scss", done => {
  expect.assertions(1);
  postcss([rule()])
    .process("@import 'file.scss';", {
      from: path.join(__dirname, "test.scss")
    })
    .then(result => {
      const warnings = result.warnings();
      expect(warnings.length).toBe(0);
      done();
    });
});

test("Import a file from a partial .scss", done => {
  expect.assertions(1);
  postcss([rule()])
    .process("@import 'file.scss';", {
      from: path.join(__dirname, "_test.scss")
    })
    .then(result => {
      const warnings = result.warnings();
      expect(warnings.length).toBe(1);
      done();
    });
});

test("Import a file from a partial .scss", done => {
  expect.assertions(1);
  postcss([rule()])
    .process('@import "file.scss";', {
      from: path.join(__dirname, "_test.scss")
    })
    .then(result => {
      const warnings = result.warnings();
      expect(warnings.length).toBe(1);
      done();
    });
});

test("Ignores empty imports (Sass will throw an error instead)", done => {
  expect.assertions(1);
  postcss([rule()])
    .process("@import '';", {
      from: path.join(__dirname, "_test.scss")
    })
    .then(result => {
      const warnings = result.warnings();
      expect(warnings.length).toBe(0);
      done();
    });
});

test("Ignores empty imports (Sass will throw an error instead)", done => {
  expect.assertions(1);
  postcss([rule()])
    .process('@import " ";', {
      from: path.join(__dirname, "_test.scss")
    })
    .then(result => {
      const warnings = result.warnings();
      expect(warnings.length).toBe(0);
      done();
    });
});

test("Import a file from a partial .scss; omitting extension", done => {
  expect.assertions(1);
  postcss([rule()])
    .process("@import 'file';", {
{'fraction_non_alphanumeric': 0.19096934548467273, 'fraction_numerical': 0.00579950289975145, 'mean_word_length': 2.997516556291391, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '6194008', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1580, 'n_words': 341}