Skip to content

Commit

Permalink
Add Lune require alias to configuration files (#35)
Browse files Browse the repository at this point in the history
The `.luaurc`, `.luau-analyze.json` and `.vscode/settings.json` now 
have an entry to configure the lune packages alias (when selecting 
the lune environment or using the lune tool)
  • Loading branch information
jeparlefrancais authored Aug 28, 2024
1 parent a1fa333 commit b4735aa
Show file tree
Hide file tree
Showing 14 changed files with 5,156 additions and 1,645 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

- add lune package aliases to configuration files ([#35](https://github.com/seaofvoices/generator-luau/pull/35))
- fix luau-lsp analysis script to ignore node_modules ([#30](https://github.com/seaofvoices/generator-luau/pull/30))
- fix incorrect extension name used in `roblox-test.sh` script ([#33](https://github.com/seaofvoices/generator-luau/pull/33))
- avoid including dev-dependencies when building Roblox models ([#32](https://github.com/seaofvoices/generator-luau/pull/32))
Expand Down
874 changes: 874 additions & 0 deletions __tests__/__recordings__/all-tools-requests_985297451/recording.har

Large diffs are not rendered by default.

1,372 changes: 1,372 additions & 0 deletions __tests__/__recordings__/default-tools-requests_3963608793/recording.har

Large diffs are not rendered by default.

104 changes: 102 additions & 2 deletions __tests__/__snapshots__/app.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`using npm Roblox environment creates a script to build a Roblox model 1`] = `
exports[`using npm Lune environment creates a .luau-analyze.json file 1`] = `
"{
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.require.directoryAliases": {
"@pkg": "node_modules/.luau-aliases",
"@lune": "~/.lune/.typedefs/0.8.8/"
}
}
"
`;

exports[`using npm Lune environment creates a .luaurc file 1`] = `
"{
"languageMode": "strict",
"lintErrors": true,
"lint": {
"*": true
},
"aliases": {
"pkg": "./node_modules/.luau-aliases",
"lune": "~/.lune/.typedefs/0.8.8/"
}
}
"
`;

exports[`using npm Roblox environment creates a .luau-analyze.json file 1`] = `
"{
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.require.directoryAliases": {
"@pkg": "node_modules/.luau-aliases"
}
}
"
`;

exports[`using npm Roblox environment creates a .luaurc file 1`] = `
"{
"languageMode": "strict",
"lintErrors": true,
"lint": {
"*": true
},
"aliases": {
"pkg": "./node_modules/.luau-aliases"
}
}
"
`;

exports[`using npm Roblox environment creates a build-roblox-model.sh file 1`] = `
"#!/bin/sh
set -e
Expand Down Expand Up @@ -75,7 +125,57 @@ exports[`using npm creates the package.json file 1`] = `
}
`;
exports[`using yarn Roblox environment creates a script to build a Roblox model 1`] = `
exports[`using yarn Lune environment creates a .luau-analyze.json file 1`] = `
"{
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.require.directoryAliases": {
"@pkg": "node_modules/.luau-aliases",
"@lune": "~/.lune/.typedefs/0.8.8/"
}
}
"
`;
exports[`using yarn Lune environment creates a .luaurc file 1`] = `
"{
"languageMode": "strict",
"lintErrors": true,
"lint": {
"*": true
},
"aliases": {
"pkg": "./node_modules/.luau-aliases",
"lune": "~/.lune/.typedefs/0.8.8/"
}
}
"
`;
exports[`using yarn Roblox environment creates a .luau-analyze.json file 1`] = `
"{
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.require.directoryAliases": {
"@pkg": "node_modules/.luau-aliases"
}
}
"
`;
exports[`using yarn Roblox environment creates a .luaurc file 1`] = `
"{
"languageMode": "strict",
"lintErrors": true,
"lint": {
"*": true
},
"aliases": {
"pkg": "./node_modules/.luau-aliases"
}
}
"
`;
exports[`using yarn Roblox environment creates a build-roblox-model.sh file 1`] = `
"#!/bin/sh
set -e
Expand Down
24 changes: 24 additions & 0 deletions __tests__/__snapshots__/foreman.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`all tools creates a foreman.toml 1`] = `
"[tools]
darklua = { github = "seaofvoices/darklua", version = "=0.13.1"}
luau-lsp = { github = "JohnnyMorganz/luau-lsp", version = "=1.32.3"}
lune = { github = "lune-org/lune", version = "=0.8.8"}
mantle = { github = "blake-mealey/mantle", version = "=0.11.16"}
rojo = { github = "rojo-rbx/rojo", version = "=7.4.4"}
run-in-roblox = { github = "rojo-rbx/run-in-roblox", version = "=0.3.0"}
selene = { github = "Kampfkarren/selene", version = "=0.27.1"}
stylua = { github = "JohnnyMorganz/StyLua", version = "=0.20.0"}
tarmac = { github = "rojo-rbx/tarmac", version = "=0.7.5"}
"
`;

exports[`default tools creates a foreman.toml 1`] = `
"[tools]
darklua = { github = "seaofvoices/darklua", version = "=0.13.1"}
luau-lsp = { github = "JohnnyMorganz/luau-lsp", version = "=1.32.3"}
selene = { github = "Kampfkarren/selene", version = "=0.27.1"}
stylua = { github = "JohnnyMorganz/StyLua", version = "=0.20.0"}
"
`;
52 changes: 26 additions & 26 deletions __tests__/app.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
import { join, dirname, basename } from 'path'
import { fileURLToPath } from 'url'
import helpers from 'yeoman-test'
import { expect, it, describe, jest, beforeEach } from '@jest/globals'

const getFileContent = (context, fileName) => {
const snapshot = context.getSnapshot(
(file) => file.relativePath && basename(file.relativePath) === fileName
)

const snapshotValues = Object.values(snapshot)
if (snapshotValues.length === 0) {
throw Error(`Unable to find file ${fileName}`)
}
if (snapshotValues.length > 1) {
throw Error(`Found multiple file for ${fileName}`)
}

return snapshotValues[0].contents
}
import { getFileContent, setupGenerator, usePolly } from './utils'

const projectName = 'new-project'
let spawnMock = jest.fn()
let answers = {}

const setupContext = async () =>
await helpers
.run(join(dirname(fileURLToPath(import.meta.url)), '../generators/app'))
await setupGenerator('app')
.withArguments([projectName])
.withAnswers(answers)
.withSpawnMock(spawnMock)

beforeEach(async () => {
beforeEach(() => {
spawnMock = jest.fn()
answers = {
name: 'Author Name',
Expand All @@ -41,6 +22,8 @@ beforeEach(async () => {
tools: [],
website: '',
}

usePolly('all-tools-requests')
})

describe.each(['npm', 'yarn'])('using %s', (packageManager) => {
Expand Down Expand Up @@ -100,10 +83,13 @@ describe.each(['npm', 'yarn'])('using %s', (packageManager) => {
answers.buildRobloxModel = true
})

it('creates a script to build a Roblox model', async () => {
const context = await setupContext()
expect(getFileContent(context, 'build-roblox-model.sh')).toMatchSnapshot()
})
it.each(['build-roblox-model.sh', '.luau-analyze.json', '.luaurc'])(
'creates a %s file',
async (fileName) => {
const context = await setupContext()
expect(getFileContent(context, fileName)).toMatchSnapshot()
}
)

describe.each(['lua', 'luau'])('using %s', (luaExtension) => {
beforeEach(async () => {
Expand All @@ -118,4 +104,18 @@ describe.each(['npm', 'yarn'])('using %s', (packageManager) => {
})
})
})

describe('Lune environment', () => {
beforeEach(async () => {
answers.luaEnvironment = 'lune'
})

it.each(['.luau-analyze.json', '.luaurc'])(
'creates a %s file',
async (fileName) => {
const context = await setupContext()
expect(getFileContent(context, fileName)).toMatchSnapshot()
}
)
})
})
88 changes: 88 additions & 0 deletions __tests__/foreman.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { expect, it, describe, jest, beforeEach } from '@jest/globals'
import { getFileContent, setupGenerator, usePolly } from './utils'

const projectName = 'new-project'
let spawnMock = jest.fn()
let answers = {}

const setupContext = async () =>
await setupGenerator('foreman')
.withArguments([projectName])
.withAnswers(answers)
.withSpawnMock(spawnMock)

beforeEach(() => {
spawnMock = jest.fn()
answers = {
tools: [],
}
})

describe('default tools', () => {
beforeEach(() => {
usePolly('default-tools-requests')
})

it('creates a foreman.toml', async () => {
const context = await setupContext()

expect(getFileContent(context, 'foreman.toml')).toMatchSnapshot()
})

it('runs the foreman install command', async () => {
await setupContext()

expect(spawnMock).toHaveBeenCalledWith(
'spawnSync',
'foreman',
['install'],
expect.any(Object)
)
})
})

describe('all tools', () => {
beforeEach(async () => {
answers.tools = [
'selene',
'stylua',
'luau-lsp',
'darklua',
'rojo',
'tarmac',
'run-in-roblox',
'lune',
'mantle',
]

usePolly('all-tools-requests')
})

it('creates a foreman.toml', async () => {
const context = await setupContext()

expect(getFileContent(context, 'foreman.toml')).toMatchSnapshot()
})

it('runs the foreman install command', async () => {
await setupContext()

expect(spawnMock).toHaveBeenCalledWith(
'spawnSync',
'foreman',
['install'],
expect.any(Object)
)
})

it('runs the lune setup command', async () => {
await setupContext()

expect(spawnMock).toHaveBeenCalledWith(
'spawnSync',
'lune',
['setup'],
expect.any(Object)
)
})
})
55 changes: 55 additions & 0 deletions __tests__/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { basename, dirname, join } from 'path'
import { afterThis } from 'jest-after-this'
import { fileURLToPath } from 'url'
import helpers from 'yeoman-test'
import { Polly } from '@pollyjs/core'
import NodeHttpAdapter from '@pollyjs/adapter-node-http'
import FSPersister from '@pollyjs/persister-fs'

export const getFileContent = (context, fileName) => {
const snapshot = context.getSnapshot(
(file) => file.relativePath && basename(file.relativePath) === fileName
)

const snapshotValues = Object.values(snapshot)
if (snapshotValues.length === 0) {
throw Error(`Unable to find file ${fileName}`)
}
if (snapshotValues.length > 1) {
throw Error(`Found multiple file for ${fileName}`)
}

return snapshotValues[0].contents
}

export const usePolly = (recordingName) => {
const location = join(
dirname(fileURLToPath(import.meta.url)),
'__recordings__'
)

const polly = new Polly(recordingName, {
adapters: [NodeHttpAdapter],
persister: FSPersister,
persisterOptions: {
fs: {
recordingsDir: location,
},
},
recordIfMissing: true,
})

polly.replay()

afterThis(() => {
polly.stop()
})
}

export const setupGenerator = (generatorName) =>
helpers.run(
join(
dirname(fileURLToPath(import.meta.url)),
`../generators/${generatorName}`
)
)
Loading

0 comments on commit b4735aa

Please sign in to comment.