Skip to content

Commit

Permalink
test: move snapshot testing to end-to-end tests
Browse files Browse the repository at this point in the history
- test: use more interesting test data
- test(unit): remove snapshots
  • Loading branch information
davla committed Oct 1, 2023
2 parents 59e8fb9 + a5b849a commit 7395317
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 157 deletions.
14 changes: 7 additions & 7 deletions test/unit/app/index.js
Expand Up @@ -29,7 +29,7 @@ describe("python-poetry-vscode", () => {
this.stubs.userGitName.returns("Jin Kazama");

this.generator = yeomanTest.run(PythonPoetryVSCodeGenerator).withAnswers({
packageName: "mandatory_package",
packageName: "tekken_2",
packageVersion: "3.18.0",
description: "I don't actually like fighting games",
});
Expand Down Expand Up @@ -58,12 +58,12 @@ describe("python-poetry-vscode", () => {
{
optionName: "author-email",
promptName: "authorEmail",
inputValue: "anna.williamsa@tekken.ie",
inputValue: "anna.williams@tekken.ie",
},
{
optionName: "repository",
promptName: "repository",
inputValue: "https://github.com/steve-fox/git_package",
inputValue: "https://github.com/anna-williams/tekken",
},
{
optionName: "license",
Expand Down Expand Up @@ -116,10 +116,10 @@ describe("python-poetry-vscode", () => {
this.composeWith.should.have.been.calledWith(
require.resolve("generator-license"),
{
email: "anna.williamsa@tekken.ie",
email: "anna.williams@tekken.ie",
license: "GPL-3.0",
name: "Anna Williams",
website: "https://github.com/steve-fox/git_package",
website: "https://github.com/anna-williams/tekken",
},
);
});
Expand All @@ -133,11 +133,11 @@ describe("python-poetry-vscode", () => {
},
{
"author-name": "Anna Williams",
"author-email": "anna.williamsa@tekken.ie",
"author-email": "anna.williams@tekken.ie",
license: "GPL-3.0",
"package-name": "tekken",
"package-version": "0.5.3",
repository: "https://github.com/steve-fox/git_package",
repository: "https://github.com/anna-williams/tekken",
description: "The King of Iron First Tournament",
"python-version": "^3.9.0",
},
Expand Down
16 changes: 8 additions & 8 deletions test/unit/lib/inputs.js
Expand Up @@ -32,17 +32,17 @@ describe("Inputs", () => {

it("defaults to the current working directory name when reading pyproject.toml is undefined", async function () {
this.generator.fs.read.returns("");
process.cwd.returns("/an/absolute/path/to/here");
process.cwd.returns("/tekken/4/steve/fox");

const promptDefault = await this.input.asPrompt().default();

promptDefault.should.equal("here");
promptDefault.should.equal("fox");
process.cwd.should.have.been.calledOnce;
});

it("defaults to null if the current working directory is not a valid python package name", async function () {
this.generator.fs.read.returns("");
process.cwd.returns("/an/absolute/path/to-here");
process.cwd.returns("/tekken/4/steve-fox");

const promptDefault = await this.input.asPrompt().default();

Expand Down Expand Up @@ -94,27 +94,27 @@ describe("Inputs", () => {
it('defaults to read "repository" from pyproject.toml', async function () {
this.generator.fs.read.returns(`
[tool.poetry]
repository = "https://github.com/hwoarang/https_package"
repository = "https://github.com/hwoarang/tekken-5"
`);

const promptDefault = await this.input.asPrompt().default();

promptDefault.should.equal("https://github.com/hwoarang/https_package");
promptDefault.should.equal("https://github.com/hwoarang/tekken-5");
this.generator.fs.read.should.have.been.calledOnce;
this.generator._queryGitOriginUrl.should.not.have.been.called;
});

[
{ protocol: "https", url: "https://github.com/hwoarang/https_package" },
{ protocol: "ssh", url: "git@github.com:hwoarang/https_package.git" },
{ protocol: "https", url: "https://github.com/hwoarang/tekken-5" },
{ protocol: "ssh", url: "git@github.com:hwoarang/tekken-5.git" },
].forEach(({ protocol, url }) => {
it(`defaults to query the url of the git "origin" remote (${protocol}) when reading pyproject.toml is undefined`, async function () {
this.generator.fs.read.returns("");
this.generator._queryGitOriginUrl.resolves(url);

const promptDefault = await this.input.asPrompt().default();

promptDefault.should.equal("https://github.com/hwoarang/https_package");
promptDefault.should.equal("https://github.com/hwoarang/tekken-5");
this.generator._queryGitOriginUrl.should.have.been.calledOnce;
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/lib/merge-config.js
Expand Up @@ -30,10 +30,10 @@ describe("mergeConfig", () => {

it("merges plain objects recursively", () => {
const dst = { a: { deep: { value: 42 } }, flag: false };
const src = { a: { deep: { file: "config.hocon" } }, flag: true };
const src = { a: { deep: { file: "Ling Xiaoyu" } }, flag: true };

mergeConfig(dst, src).should.deep.equal({
a: { deep: { value: 42, file: "config.hocon" } },
a: { deep: { value: 42, file: "Ling Xiaoyu" } },
flag: true,
});
});
Expand Down
12 changes: 6 additions & 6 deletions test/unit/poetry/index.js
Expand Up @@ -26,7 +26,7 @@ const generatorInput = [
optionName: "package-name",
promptName: "packageName",
outputPath: "name",
inputValue: "input_package",
inputValue: "tekken_6",
},
{
optionName: "package-version",
Expand All @@ -38,7 +38,7 @@ const generatorInput = [
optionName: "description",
promptName: "description",
outputPath: "description",
inputValue: "Input description",
inputValue: "I don't actually like fighting games",
},
{
optionName: "license",
Expand All @@ -56,21 +56,21 @@ const generatorInput = [
optionName: "repository",
promptName: "repository",
outputPath: "repository",
inputValue: "https://github.com/marshall-law/input_package",
inputValue: "https://github.com/marshall-law/tekken-6",
},
];

const mandatoryAnswers = {
packageName: "mandatory_package",
packageName: "tekken_7",
packageVersion: "1.9.0",
description: "Non-empty description",
description: "The King of Iron Fist Tournament",
};

describe("python-poetry-vscode:poetry", () => {
beforeEach(function () {
this.stubs = setupSystemAccessStubs();
this.stubs.queryGitOriginUrl.resolves(
"https://github.com/eddy-gordo/git_package",
"https://github.com/eddy-gordo/tekken-5",
);
this.stubs.spawnCommand
.withArgs("python", ["--version"], { stdio: "pipe" })
Expand Down
17 changes: 0 additions & 17 deletions test/unit/python-package/__snapshots__/index.js.snap

This file was deleted.

38 changes: 3 additions & 35 deletions test/unit/python-package/index.js
Expand Up @@ -2,17 +2,15 @@ import path from "node:path";

import yeomanTest from "yeoman-test";

import "../../lib/register-chai-snapshots.js";
import PythonPackageGenerator from "../../../generators/python-package/index.js";
import { readFileInCwd } from "../../lib/file-system.js";
import restoreRunResult from "../../lib/generator-hooks.js";
import { withInput } from "../../lib/yeoman-test-input.js";

const generatorInput = [
{
optionName: "package-name",
promptName: "packageName",
inputValue: "package_name",
inputValue: "tekken_7",
},
{
optionName: "package-version",
Expand All @@ -34,17 +32,7 @@ describe("python-poetry-vscode:python-package", () => {

it("should create __init__.py in a directory named after the package", async function () {
this.runResult = await this.generator;

this.runResult.assertFile(path.join("package_name", "__init__.py"));
});

it("should populate the pacakge __init__.py file", async function () {
this.runResult = await this.generator;
const fileContent = await readFileInCwd(
this.runResult,
path.join("package_name", "__init__.py"),
);
fileContent.should.matchSnapshot();
this.runResult.assertFile(path.join("tekken_7", "__init__.py"));
});
});

Expand All @@ -53,32 +41,12 @@ describe("python-poetry-vscode:python-package", () => {

it("should create __init__.py in the tests directory", async function () {
this.runResult = await this.generator;

this.runResult.assertFile(path.join("tests", "__init__.py"));
});

it("should populate the test __init__.py file", async function () {
this.runResult = await this.generator;
const fileContent = await readFileInCwd(
this.runResult,
path.join("tests", "__init__.py"),
);
fileContent.should.matchSnapshot();
});

it("should create a tests file named after the package in the tests directory", async function () {
this.runResult = await this.generator;

this.runResult.assertFile(path.join("tests", "test_package_name.py"));
});

it("should populate the test file", async function () {
this.runResult = await this.generator;
const fileContent = await readFileInCwd(
this.runResult,
path.join("tests", "test_package_name.py"),
);
fileContent.should.matchSnapshot();
this.runResult.assertFile(path.join("tests", "test_tekken_7.py"));
});
});
});
69 changes: 0 additions & 69 deletions test/unit/vscode/__snapshots__/index.js.snap

This file was deleted.

15 changes: 2 additions & 13 deletions test/unit/vscode/index.js
Expand Up @@ -3,7 +3,6 @@ import path from "node:path";

import yeomanTest from "yeoman-test";

import "../../lib/register-chai-snapshots.js";
import VSCodeGenerator from "../../../generators/vscode/index.js";
import {
readJsonInCwd,
Expand Down Expand Up @@ -42,11 +41,6 @@ describe("python-poetry-vscode:vscode", () => {
this.runResult.assertFile(filePath);
await readJsonInCwd(this.runResult, filePath).should.be.fulfilled;
});

it(`populates ${toPosixPath(filePath)}`, async function () {
this.runResult = await this.generator;
(await readJsonInCwd(this.runResult, filePath)).should.matchSnapshot();
});
}

it(`merges .vscode/settings.json with existing content`, async function () {
Expand Down Expand Up @@ -101,11 +95,6 @@ describe("python-poetry-vscode:vscode", () => {
this.runResult.assertFile(filePath);
await readTomlInCwd(this.runResult, filePath).should.be.fulfilled;
});

it(`populates ${toPosixPath(filePath)}`, async function () {
this.runResult = await this.generator;
(await readTomlInCwd(this.runResult, filePath)).should.matchSnapshot();
});
}

it("merges poetry.toml with existing content", async function () {
Expand All @@ -129,7 +118,7 @@ describe("python-poetry-vscode:vscode", () => {
tool: {
poetry: {
dependencies: { pylint: "^2.15.0" },
name: "existing_package",
name: "tekken",
},
},
};
Expand All @@ -146,7 +135,7 @@ describe("python-poetry-vscode:vscode", () => {
isort: "^5.12.0",
pylint: "^2.15.0",
},
name: "existing_package",
name: "tekken",
},
},
});
Expand Down

0 comments on commit 7395317

Please sign in to comment.