/
generateCertificate.js
39 lines (30 loc) 路 1.2 KB
/
generateCertificate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const assert = require('assert');
const path = require('path');
const fs = require('@parcel/fs');
const generateCertificate = require('../src/utils/generateCertificate');
const {rimraf, ncp} = require('./utils');
const cachePath = path.join(__dirname, '.cache');
const inputPath = path.join(__dirname, '/input');
const cacheOptions = {
cacheDir: cachePath,
cache: true
};
describe('generateCertificate', () => {
beforeEach(async () => {
await rimraf(cachePath);
await rimraf(inputPath);
});
it('should support loading cached certificate', async () => {
await ncp(path.join(__dirname, '/integration/https'), cachePath);
const key = await fs.readFile(path.join(cachePath, 'private.pem'));
const cert = await fs.readFile(path.join(cachePath, 'primary.crt'));
const generated = generateCertificate(cacheOptions);
assert.equal(generated.cert.toString(), cert.toString());
assert.equal(generated.key.toString(), key.toString());
});
it('should support caching generated certificate', async () => {
generateCertificate(cacheOptions);
assert(await fs.exists(path.join(cachePath, 'private.pem')));
assert(await fs.exists(path.join(cachePath, 'primary.crt')));
});
});