Skip to content

Commit fd856cd

Browse files
committed
tests: fix
1 parent 3706dae commit fd856cd

File tree

3 files changed

+35
-123
lines changed

3 files changed

+35
-123
lines changed

Makefile

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
11
TESTS_INIT=tests/minimal_init.lua
22
TESTS_DIR=tests/
33

4-
plugin_files = $(wildcard plugin/*.ts)
5-
plugin_out_files = $(plugin_files:plugin/%.ts=plugin/%.lua)
6-
test_init= $(wildcard tests/*.ts)
7-
test_files =$(wildcard tests/**/*.ts)
8-
test_out_files = $(test_files:tests/%.ts=tests/%.lua)
9-
test_out_init = $(test_init:tests/%.ts=tests/%.lua)
10-
11-
12-
compile: node_modules
13-
mkdir -p lua/forem-nvim
14-
npx tstl
15-
npx tstl -p plugin/tsconfig.json
16-
npx tstl -p tests/tsconfig.json
17-
18-
node_modules: package.json
19-
@test -d node_modules || npm clean-install
20-
21-
test: compile
4+
test:
225
@nvim \
236
--headless \
247
--noplugin \
258
-u ${TESTS_INIT} \
269
-c "PlenaryBustedDirectory ${TESTS_DIR} { minimal_init = '${TESTS_INIT}' }"
2710

28-
.PHONY: test compile
11+
.PHONY: test

tests/forem-nvim/setup_spec.lua

+33-23
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ local stub = require("luassert.stub")
33
local spy = require("luassert.spy")
44
local match = require("luassert.match")
55
local article = require("forem-nvim.article")
6+
local busted = require("plenary.busted")
7+
local describe = busted.describe
8+
local before_each = busted.before_each
9+
local after_each = busted.after_each
10+
local it = busted.it
611

7-
local function mockInternal(module)
12+
local function mock_internal(module)
813
_G.package.loaded["forem-nvim"] = nil
914
_G.package.loaded[module] = nil
1015
local mocked = require(module)
@@ -14,63 +19,68 @@ end
1419
describe(
1520
"Forem.nvim",
1621
function()
17-
local foremNvim
22+
local forem_nvim
1823
local snapshot
24+
1925
before_each(function()
2026
vim.env.FOREM_API_KEY = "foo"
2127
_G.package.loaded["forem-nvim"] = nil
22-
foremNvim = require("forem-nvim")
28+
forem_nvim = require("forem-nvim")
2329
snapshot = assert:snapshot()
2430
end)
31+
2532
after_each(function()
2633
snapshot:revert()
2734
end)
35+
2836
it(
2937
"should show a notification when no api key is set",
3038
function()
3139
vim.env.FOREM_API_KEY = nil
3240
stub.new(vim, "notify")
33-
foremNvim.my_articles()
41+
forem_nvim.my_articles()
3442
assert.stub(vim.notify).was.called()
3543
end
3644
)
45+
3746
it(
3847
"should call the api to get the articles",
3948
function()
40-
local mockedApi = mockInternal("forem-nvim.api")
41-
mockedApi.myArticles = spy.new(function()
49+
local mocked_api = mock_internal("forem-nvim.api")
50+
mocked_api.my_articles = spy.new(function()
4251
end)
43-
local foremNvimMocked = require("forem-nvim")
44-
foremNvimMocked.my_articles()
45-
assert.spy(mockedApi.myArticles).was.called()
52+
local forem_nvim_mocked = require("forem-nvim")
53+
forem_nvim_mocked.my_articles()
54+
assert.spy(mocked_api.my_articles).was.called()
4655
end
4756
)
57+
4858
it(
4959
"should create a new article and open it",
5060
function()
5161
local input = stub.new(vim.fn, "input")
5262
input.returns("Title")
53-
local api = mockInternal("forem-nvim.api")
54-
local apiNewArticle = stub.new(api, "newArticle")
55-
local newArticle = {
63+
local api = mock_internal("forem-nvim.api")
64+
local api_new_article = stub.new(api, "new_article")
65+
local new_article = {
5666
id = 1,
5767
body_markdown = article.get_template("Title")
5868
}
59-
apiNewArticle.returns({ status = 201, body = newArticle })
60-
local buffer = mockInternal("forem-nvim.buffer")
61-
local bufferOpenMyArticle = spy.on(buffer, "openMyArticle")
62-
local foremNvimMocked = require("forem-nvim")
63-
foremNvimMocked.new_article()
64-
assert.stub(apiNewArticle).was.called_with("Title")
65-
assert.spy(bufferOpenMyArticle).was_called_with(match.is_same(newArticle))
69+
api_new_article.returns({ status = 201, body = new_article })
70+
local buffer = mock_internal("forem-nvim.buffer")
71+
local buffer_open_my_article = spy.on(buffer, "open_my_article")
72+
local forem_nvim_mocked = require("forem-nvim")
73+
forem_nvim_mocked.new_article()
74+
assert.stub(api_new_article).was.called_with("Title")
75+
assert.spy(buffer_open_my_article).was_called_with(match.is_same(new_article))
6676
assert.are.same(
67-
"forem://my-article/" .. tostring(newArticle.id),
77+
"forem://my-article/" .. tostring(new_article.id),
6878
vim.api.nvim_buf_get_name(0)
6979
)
70-
local bufferContent = vim.api.nvim_buf_get_lines(0, 0, -1, true)
80+
local buffer_content = vim.api.nvim_buf_get_lines(0, 0, -1, true)
7181
assert.are.same(
72-
article.get_body_lines(newArticle),
73-
bufferContent
82+
article.get_body_lines(new_article),
83+
buffer_content
7484
)
7585
end
7686
)

tests/forem-nvim/setup_spec.ts

-81
This file was deleted.

0 commit comments

Comments
 (0)