Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions __tests__/postInstall/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { describe, after, before, test, mock as mockit, beforeEach, afterEach } from "node:test"
import assert from "node:assert"

import { createConfig } from '../../dist/utils.js'

import mock from 'mock-fs'
import fs, { readdirSync, readFileSync } from 'node:fs'
import { json } from "node:stream/consumers"
import { config } from "node:process"
import { randomUUID } from "node:crypto"


export function postInstall() {


describe('postInstall runs properly', () => {
beforeEach(() => {
mock({
'dist': {},
})
})

afterEach(() => {
mock.restore();
})

test('No config creates dir', (t) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for calling createConfig() with out a directory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

const configFileExists = createConfig('dist/.fa')
assert.equal(configFileExists, true, 'Config not created at dist/.fa/config.json')
})
test('No config creates full config file with expected types', (t) => {
const configFileExists = createConfig('dist/.fa')
const configObject = JSON.parse(readFileSync('dist/.fa/config.json'))
assert(configObject.telemetry, true, 'Default telemetry not set to true')
assert(typeof configObject.id, 'string', "ID doesn't exist or isn't a string")
})

test('Complete config returns false', (t) => {
before(() => {
mock({
dist: {
'.fa': {
'config.json': JSON.stringify({id: '8c0a77f2-27e4-4284-b5d3-5618ec2a56eb', telemetry: true})
}
}
})
})
assert.equal(createConfig('dist/.fa'), false, 'Postinstall did not return false properly')
})
test('No ID in config, but telemetry false', (t) => {
before(() => {
mock({
dist: {
'.fa': {
'config.json': JSON.stringify({telemetry: false})
}
}
})
})
createConfig('dist/.fa')
const configObject = JSON.parse(fs.readFileSync('dist/.fa/config.json'))
assert.equal(typeof configObject.id, 'string', 'No ID after run')
assert.equal(configObject.telemetry, false, 'Telemetry got reset')
})
test('No telemetry in config, but ID', (t) => {
before(() => {
mock({
dist: {
'.fa': {
'config.json': JSON.stringify({id: '8c0a77f2-27e4-4284-b5d3-5618ec2a56eb'})
}
}
})
})
createConfig('dist/.fa')
const configObject = JSON.parse(fs.readFileSync('dist/.fa/config.json'))
assert.equal(configObject.id, '8c0a77f2-27e4-4284-b5d3-5618ec2a56eb', 'ID got reset')
assert.equal(configObject.telemetry, true, 'Telemetry did not get set')
})


})


}
4 changes: 4 additions & 0 deletions __tests__/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { postInstall } from "./postInstall/index.js";


postInstall()
Loading