Skip to content

Commit

Permalink
fix(pods): handle stub notes correctly on import
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinslin committed Sep 14, 2020
1 parent 9a40d8e commit df22b59
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/pods-core/src/builtin/JSONPod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export class JSONImportPod extends ImportPodBaseV2<ImportPodConfig> {
const entries = fs.readJSONSync(src.fsPath);
const notes = await this._entries2Notes(entries, { destName, concatenate });
return Promise.all(
_.map(notes, (n) => this.engine.write(n, { newNode: true }))
_.map(notes, (n) =>
this.engine.write(n, { newNode: true, parentsAsStubs: true })
)
);
}

Expand Down
35 changes: 34 additions & 1 deletion packages/pods-core/src/builtin/__tests__/JSONPod.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { DNodeRawProps, Note, NoteRawProps } from "@dendronhq/common-all";
import {
DNode,
DNodeRawProps,
DNodeUtils,
Note,
NoteRawProps,
} from "@dendronhq/common-all";
import {
EngineTestUtils,
FileTestUtils,
Expand Down Expand Up @@ -126,6 +132,33 @@ describe("JSONImportPod", () => {
).toBeTruthy();
});

test("basic w/stubs", async () => {
({ storeDir, importSrc } = await setupImport({
jsonEntries: createJSON().concat([
{ fname: "baz.one", body: "baz body" },
]),
}));
wsRoot = path.dirname(importSrc).split("/").slice(0, -1).join("/");
const pod = new JSONImportPod({ roots: [storeDir], wsRoot });
const config: JSONImportPodConfig = {
src: importSrc,
concatenate: false,
};
await pod.plant({ mode, config });
let [expectedFiles, actualFiles] = FileTestUtils.cmpFiles(storeDir, [], {
add: ["root.md", "foo.md", "bar.md", "baz.one.md"],
});
expect(expectedFiles).toEqual(actualFiles);
const stubNote = DNodeUtils.getNoteByFname("baz", pod.engine) as Note;
expect(stubNote.stub).toBeTruthy();
const importedNote = fs.readFileSync(path.join(storeDir, "foo.md"), {
encoding: "utf8",
});
expect(
_.every(["foo body"], (ent) => importedNote.match(ent))
).toBeTruthy();
});

test("basic w/rel path", async () => {
const pod = new JSONImportPod({ roots: [storeDir], wsRoot });
const dirname = path.dirname(importSrc).split("/").slice(-1)[0];
Expand Down

0 comments on commit df22b59

Please sign in to comment.