21 lines
1.7 KiB
JavaScript
21 lines
1.7 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fixture, workspace } from './helpers.mjs';
|
|
import { Store } from '../src/server/store.mjs';
|
|
import { initializeExampleProject } from '../src/core/initial-example-project.mjs';
|
|
import { snapshotPersistentData } from '../src/core/desktop/install-manager.mjs';
|
|
|
|
test('a starter is copied into user data once; restarting from another program version preserves existing projects and editable bytes', t => {
|
|
const f = fixture(t), store = new Store(path.join(f.root, 'empty-data')); f.onCleanup(() => store.close());
|
|
const source = fs.readFileSync(path.join(workspace, 'examples/starter-project/README.md'));
|
|
const example = initializeExampleProject(store, workspace); assert.ok(example.root.startsWith(store.directory + path.sep)); assert.equal(store.projects.length, 1);
|
|
const file = path.join(example.root, 'README.md'); fs.appendFileSync(file, '\nOwned user change\n'); const edited = fs.readFileSync(file), snapshot = snapshotPersistentData(store.directory);
|
|
assert.equal(initializeExampleProject(store, path.join(f.root, 'different-version')).id, example.id); assert.deepEqual(snapshotPersistentData(store.directory), snapshot); assert.deepEqual(fs.readFileSync(file), edited);
|
|
assert.deepEqual(fs.readFileSync(path.join(workspace, 'examples/starter-project/README.md')), source);
|
|
});
|
|
test('startup does not insert a demo or rewrite/reorder an existing user project registry', t => {
|
|
const f = fixture(t), before = snapshotPersistentData(f.data); assert.equal(initializeExampleProject(f.store, workspace), null); assert.deepEqual(snapshotPersistentData(f.data), before);
|
|
});
|