<commit_before>import test from "./helpers/avaEx"
import { assertPack, modifyPackageJson, outDirName } from "./helpers/packTester"
import { move, outputFile, outputJson } from "fs-extra-p"
import { Promise as BluebirdPromise } from "bluebird"
import * as path from "path"
import { assertThat } from "./helpers/fileAssert"
import { Platform, PackagerOptions } from "out"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/awaiter")

test("custom buildResources dir", () => assertPack("test-app-one", allPlatformsAndCurrentArch(), {
  tempDirCreated: projectDir => BluebirdPromise.all([
    modifyPackageJson(projectDir, data => {
      data.directories = {
        buildResources: "custom"
      }
    }),
    move(path.join(projectDir, "build"), path.join(projectDir, "custom"))
  ])
}))

test("custom output dir", () => assertPack("test-app-one", allPlatformsAndCurrentArch(false), {
  tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
    data.directories = {
      output: "customDist"
    }
  }),
  packed: async (projectDir) => {
    await assertThat(path.join(projectDir, "customDist")).isDirectory()
  }
}))

test("productName with space", () => assertPack("test-app-one", allPlatformsAndCurrentArch(), {
  tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
    data.productName = "Test App"
  })
}))

test("build in the app package.json", t => t.throws(assertPack("test-app", allPlatformsAndCurrentArch(), {
  tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
    data.build = {
      "iconUrl": "bar",
    }
  }, true)
}), /'build' in the application package\.json .+/))

test("invalid main in the app package.json", t => t.throws(assertPack("test-app", allPlatformsAndCurrentArch(false), {
  tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
    data.main = "main.js"
  }, true)
}), "Application entry file main.js could not be found in package. Seems like a wrong configuration."))

test("invalid main in the app package.json (no asar)", t => t.throws(assertPack("test-app", allPlatformsAndCurrentArch(false), {
  tempDirCreated: projectDir => {
    return BluebirdPromise.all([
      modifyPackageJson(projectDir, data => {
        data.main = "main.js"
      }, true),
      modifyPackageJson(projectDir, data => {
        data.build.asar = false
      })
    ])
  }
}), "Application entry file main.js could not be found in package. Seems like a wrong configuration."))

test("main in the app package.json (no asar)", () => assertPack("test-app", allPlatformsAndCurrentArch(false), {
  tempDirCreated: projectDir => {
    return BluebirdPromise.all([
      move(path.join(projectDir, "app", "index.js"), path.join(projectDir, "app", "main.js")),
      modifyPackageJson(projectDir, data => {
        data.main = "main.js"
      }, true),
      modifyPackageJson(projectDir, data => {
        data.build.asar = false
      })
    ])
  }
}))

test("version from electron-prebuilt dependency", () => assertPack("test-app-one", {
  platform: [Platform.fromString(process.platform)],
  dist: false
}, {
  tempDirCreated: projectDir => {
    return BluebirdPromise.all([
      outputJson(path.join(projectDir, "node_modules", "electron-prebuilt", "package.json"), {
        version: "0.37.7"
      }),
      modifyPackageJson(projectDir, data => {
        data.devDependencies = {}
      })
    ])
  }
}))

test("www as default dir", () => assertPack("test-app", {
  platform: [Platform.fromString(process.platform)],
}, {
  tempDirCreated: projectDir => BluebirdPromise.all([
    move(path.join(projectDir, "app"), path.join(projectDir, "www"))
  ])
}))

test("copy extra resource", async () => {
  for (let platform of getPossiblePlatforms()) {
    const osName = platform.buildConfigurationKey<commit_msg>test: Application entry can't be found #371<commit_after>import test from "./helpers/avaEx"
import { assertPack, modifyPackageJson, outDirName } from "./helpers/packTester"
import { move, outputFile, outputJson } from "fs-extra-p"
import { Promise as BluebirdPromise } from "bluebird"
import * as path from "path"
import { assertThat } from "./helpers/fileAssert"
import { Platform, PackagerOptions } from "out"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/awaiter")

test("custom buildResources dir", () => assertPack("test-app-one", allPlatformsAndCurrentArch(), {
  tempDirCreated: projectDir => BluebirdPromise.all([
    modifyPackageJson(projectDir, data => {
      data.directories = {
        buildResources: "custom"
      }
    }),
    move(path.join(projectDir, "build"), path.join(projectDir, "custom"))
  ])
}))

test("custom output dir", () => assertPack("test-app-one", allPlatformsAndCurrentArch(false), {
  tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
    data.directories = {
      output: "customDist"
    }
  }),
  packed: async (projectDir) => {
    await assertThat(path.join(projectDir, "customDist")).isDirectory()
  }
}))

test("productName with space", () => assertPack("test-app-one", allPlatformsAndCurrentArch(), {
  tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
    data.productName = "Test App"
  })
}))

test("build in the app package.json", t => t.throws(assertPack("test-app", allPlatformsAndCurrentArch(), {
  tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
    data.build = {
      "iconUrl": "bar",
    }
  }, true)
}), /'build' in the application package\.json .+/))

test("invalid main in the app package.json", t => t.throws(assertPack("test-app", allPlatformsAndCurrentArch(false), {
  tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
    data.main = "main.js"
  }, true)
}), "Application entry file main.js could not be found in package. Seems like a wrong configuration."))

test("invalid main in the app package.json (no asar)", t => t.throws(assertPack("test-app", allPlatformsAndCurrentArch(false), {
  tempDirCreated: projectDir => {
    return BluebirdPromise.all([
      modifyPackageJson(projectDir, data => {
        data.main = "main.js"
      }, true),
      modifyPackageJson(projectDir, data => {
        data.build.asar = false
      })
    ])
  }
}), "Application entry file main.js could not be found in package. Seems like a wrong configuration."))

test("main in the app package.json (no asar)", () => assertPack("test-app", allPlatformsAndCurrentArch(false), {
  tempDirCreated: projectDir => {
    return BluebirdPromise.all([
      move(path.join(projectDir, "app", "index.js"), path.join(projectDir, "app", "main.js")),
      modifyPackageJson(projectDir, data => {
        data.main = "main.js"
      }, true),
      modifyPackageJson(projectDir, data => {
        data.build.asar = false
      })
    ])
  }
}))


test("relative index", () => assertPack("test-app", allPlatformsAndCurrentArch(false), {
  tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
    data.main = "./index.js"
  }, true)
}))

test("version from electron-prebuilt dependency", () => assertPack("test-app-one", {
  platform: [Platform.fromString(process.platform)],
  dist: false
}, {
  tempDirCreated: projectDir => {
    return BluebirdPromise.all([
      outputJson(path.join(projectDir, "node_modules", "electron-prebuilt", "package.json"), {
        version: "0.37.7"
      }),
      modifyPackageJson(projectDir, data => {
        data.devDependencies = {}
      })
    ])
  }
}))

test("www as default dir", () => assertPack("test-app", {
  platform: [Platform.fromString(process.platform)],
}, {
  tempDirCreated: projectDir => BluebirdPromise.all([
    move(path.join(projectDir, "app"), path.join(projectDir, "www"))
  ])
}))

test("copy extra resource", async () => {
  for (let platform of getPossiblePlatforms()) {
    const osName = platform.buildConfigurationKey
{'fraction_non_alphanumeric': 0.1548149090446508, 'fraction_numerical': 0.0013993130644956112, 'mean_word_length': 4.059202059202059, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4854333', 'n_tokens_mistral': 2373, 'n_tokens_neox': 2376, 'n_words': 526}