diff --git a/spec/asar-spec.coffee b/spec/asar-spec.coffee new file mode 100644 index 000000000000..397255581825 --- /dev/null +++ b/spec/asar-spec.coffee @@ -0,0 +1,31 @@ +assert = require 'assert' +fs = require 'fs' +path = require 'path' + +describe 'asar package', -> + fixtures = path.join __dirname, 'fixtures' + + describe 'node api', -> + describe 'fs.readFileSync', -> + it 'reads a normal file', -> + file1 = path.join fixtures, 'asar', 'a.asar', 'file1' + assert.equal fs.readFileSync(file1).toString(), 'file1\n' + file2 = path.join fixtures, 'asar', 'a.asar', 'file2' + assert.equal fs.readFileSync(file2).toString(), 'file2\n' + file3 = path.join fixtures, 'asar', 'a.asar', 'file3' + assert.equal fs.readFileSync(file3).toString(), 'file3\n' + + it 'reads a linked file', -> + p = path.join fixtures, 'asar', 'a.asar', 'link1' + assert.equal fs.readFileSync(p).toString(), 'file1\n' + + it 'reads a file from linked directory', -> + p = path.join fixtures, 'asar', 'a.asar', 'link2', 'file1' + assert.equal fs.readFileSync(p).toString(), 'file1\n' + p = path.join fixtures, 'asar', 'a.asar', 'link2', 'link2', 'file1' + assert.equal fs.readFileSync(p).toString(), 'file1\n' + + it 'throws ENOENT error when can not find a file', -> + p = path.join fixtures, 'asar', 'a.asar', 'not-exist' + throws = -> fs.readFileSync p + assert.throws throws, /ENOENT/ diff --git a/spec/fixtures/asar/a.asar b/spec/fixtures/asar/a.asar new file mode 100644 index 000000000000..7f04d34f6040 Binary files /dev/null and b/spec/fixtures/asar/a.asar differ