<commit_before>import childProcess, { execSync } from "child_process";
import { promisify } from "util";
import path from "path";
import fs from "fs";
const projectRoot = path.resolve(__dirname, "../..");
const exec = promisify(childProcess.exec);
const packageJson = require(path.resolve(projectRoot, "package.json"));
const mainFilePath = path.resolve(
  projectRoot,
  packageJson.bin["kintone-data-loader"]
);

const checkRejectArg = ({
  arg,
  errorMessage,
}: {
  arg: string;
  errorMessage: string;
}) => {
  return expect(
    exec(`cross-env LC_ALL='en_US' node ${mainFilePath} ${arg}`)
  ).rejects.toThrow(errorMessage);
};

describe("main", () => {
  beforeEach(() => {
    if (!fs.existsSync(mainFilePath)) {
      execSync("npm run build");
    }
  });
  it("should throw error when no commands are passed", () => {
    return checkRejectArg({
      arg: "",
      errorMessage: "Not enough non-option arguments: got 0, need at least 1",
    });
  });
  it("should throw error when an undefined command is passed", () => {
    return checkRejectArg({
      arg: "dummy",
      errorMessage: "Unknown argument: dummy",
    });
  });
  it("should throw error when an undefined argument is passed", () => {
    return checkRejectArg({
      arg: "import --dummy",
      errorMessage: "Unknown argument: dummy",
    });
  });
});
<commit_msg>test: run build script before tests in main.test.ts of data-loader (#661)<commit_after>import childProcess, { execSync } from "child_process";
import { promisify } from "util";
import path from "path";
import fs from "fs";
const projectRoot = path.resolve(__dirname, "../..");
const exec = promisify(childProcess.exec);
const packageJson = require(path.resolve(projectRoot, "package.json"));
const mainFilePath = path.resolve(
  projectRoot,
  packageJson.bin["kintone-data-loader"]
);

const checkRejectArg = ({
  arg,
  errorMessage,
}: {
  arg: string;
  errorMessage: string;
}) => {
  return expect(
    exec(`cross-env LC_ALL='en_US' node ${mainFilePath} ${arg}`)
  ).rejects.toThrow(errorMessage);
};

describe("main", () => {
  beforeAll(() => {
    execSync("npm run build");
  });
  it("should throw error when no commands are passed", () => {
    return checkRejectArg({
      arg: "",
      errorMessage: "Not enough non-option arguments: got 0, need at least 1",
    });
  });
  it("should throw error when an undefined command is passed", () => {
    return checkRejectArg({
      arg: "dummy",
      errorMessage: "Unknown argument: dummy",
    });
  });
  it("should throw error when an undefined argument is passed", () => {
    return checkRejectArg({
      arg: "import --dummy",
      errorMessage: "Unknown argument: dummy",
    });
  });
});

{'fraction_non_alphanumeric': 0.16010305483989695, 'fraction_numerical': 0.002576370997423629, 'mean_word_length': 3.743455497382199, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4481877', 'n_tokens_mistral': 833, 'n_tokens_neox': 818, 'n_words': 232}