๐Ÿ“ฆ ionic-team / capacitor

๐Ÿ“„ init.spec.ts ยท 48 lines
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
40
41
42
43
44
45
46
47
48import { mkdir } from 'fs-extra';
import { join } from 'path';

import { APP_ID, APP_NAME, run, mktmp, MappedFS } from './util';

describe('Init', () => {
  let appDirObj: any;
  let tmpDir: string;
  let appDir: string;
  let FS: MappedFS;

  beforeAll(async () => {
    // These commands are slowww...
    jest.setTimeout(150000);
    appDirObj = await mktmp();
    tmpDir = appDirObj.path;
    appDir = join(tmpDir, 'test-app');
    await mkdir(appDir);
    FS = new MappedFS(appDir);
  });

  afterAll(() => {
    appDirObj.cleanupCallback();
  });

  it('Should init a project', async () => {
    await run(appDir, `init "${APP_NAME}" "${APP_ID}"`);
    expect(await FS.exists('capacitor.config.json')).toBe(true);

    const fileContents = await FS.read('capacitor.config.json');
    const jsonContents = JSON.parse(fileContents);
    expect(jsonContents.appId).toEqual(APP_ID);
    expect(jsonContents.appName).toEqual(APP_NAME);
    expect(jsonContents.webDir).toEqual('www');
  });

  it('Should init a project with webDir set', async () => {
    await run(appDir, `init "${APP_NAME}" "${APP_ID}" --web-dir="build"`);
    expect(await FS.exists('capacitor.config.json')).toBe(true);

    const fileContents = await FS.read('capacitor.config.json');
    const jsonContents = JSON.parse(fileContents);
    expect(jsonContents.appId).toEqual(APP_ID);
    expect(jsonContents.appName).toEqual(APP_NAME);
    expect(jsonContents.webDir).toEqual('build');
  });
});