asar.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict'
  2. const common = require('../common')
  3. const fs = require('fs-extra')
  4. const path = require('path')
  5. const test = require('ava')
  6. const util = require('./_util')
  7. test('asar argument test: asar is not set', t => {
  8. const asarOpts = common.createAsarOpts({})
  9. t.false(asarOpts, 'createAsarOpts returns false')
  10. })
  11. test('asar argument test: asar is true', t => {
  12. t.deepEqual(common.createAsarOpts({asar: true}), {})
  13. })
  14. test('asar argument test: asar is not an Object or a bool', t => {
  15. t.false(common.createAsarOpts({asar: 'string'}), 'createAsarOpts returns false')
  16. })
  17. util.testSinglePlatform('default_app.asar removal test', (t, opts) => {
  18. opts.name = 'default_appASARTest'
  19. opts.dir = util.fixtureSubdir('el-0374')
  20. opts.electronVersion = '0.37.4'
  21. return util.packageAndEnsureResourcesPath(t, opts)
  22. .then(resourcesPath => fs.pathExists(path.join(resourcesPath, 'default_app.asar')))
  23. .then(exists => t.false(exists, 'The output directory should not contain the Electron default_app.asar file'))
  24. })
  25. util.testSinglePlatform('asar test', (t, opts) => {
  26. opts.name = 'asarTest'
  27. opts.dir = util.fixtureSubdir('basic')
  28. opts.asar = {
  29. 'unpack': '*.pac',
  30. 'unpackDir': 'dir_to_unpack'
  31. }
  32. let resourcesPath
  33. return util.packageAndEnsureResourcesPath(t, opts)
  34. .then(generatedResourcesPath => {
  35. resourcesPath = generatedResourcesPath
  36. return fs.stat(path.join(resourcesPath, 'app.asar'))
  37. }).then(stats => {
  38. t.true(stats.isFile(), 'app.asar should exist under the resources subdirectory when opts.asar is true')
  39. return fs.pathExists(path.join(resourcesPath, 'app'))
  40. }).then(exists => {
  41. t.false(exists, 'app subdirectory should NOT exist when app.asar is built')
  42. return fs.stat(path.join(resourcesPath, 'app.asar.unpacked'))
  43. }).then(stats => {
  44. t.true(stats.isDirectory(), 'app.asar.unpacked should exist under the resources subdirectory when opts.asar_unpack is set some expression')
  45. return fs.stat(path.join(resourcesPath, 'app.asar.unpacked', 'dir_to_unpack'))
  46. }).then(stats => t.true(stats.isDirectory(), 'dir_to_unpack should exist under app.asar.unpacked subdirectory when opts.asar-unpack-dir is set dir_to_unpack'))
  47. })