-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass site_config as an optional arg.
This change passes a path to a site_config into vite.js's proxyOptions so callers that don't have a standard `sites/` layout (eg frappe press dashboard - potentially any caller using frappe-ui as a lib) can configure the `webserver_port`. Also includes basic node test run via `node --test ./vite.test.js`.
- Loading branch information
1 parent
bb6bce9
commit 157aace
Showing
2 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const { describe, it, afterEach, beforeEach } = require('node:test') | ||
const frappeui = require('./vite.js') | ||
const fs = require('fs/promises') | ||
const path = require('path') | ||
const assert = require('assert') | ||
const os = require('os') | ||
|
||
|
||
describe('Test site_config resolution', () => { | ||
|
||
let tmpDir | ||
let site_config_path | ||
let cwd | ||
const jsonData = { webserver_port: "1001" } | ||
const proxySource = '^/(app|login|api|assets|files)' | ||
const localhostTarget = 'http://127.0.0.1' | ||
|
||
beforeEach(async () => { | ||
dirPath = path.join(os.tmpdir(), ts()) | ||
tmpDir = await fs.mkdtemp(dirPath) | ||
await fs.mkdir(path.join(tmpDir, 'sites')) | ||
await fs.mkdir(path.join(tmpDir, 'apps')) | ||
const sitesDir = path.join(tmpDir, 'sites') | ||
scp = path.join(sitesDir, 'common_site_config.json') | ||
await fs.writeFile(scp, JSON.stringify(jsonData), 'utf8') | ||
|
||
// TODO: avoid chdir in tests. Unfortunately the code under test uses | ||
// relative paths, and changing that will need a bigger change than | ||
// simply doing this. | ||
cwd = process.cwd() | ||
process.chdir(sitesDir) | ||
}) | ||
|
||
afterEach(async () => { | ||
process.chdir(cwd) | ||
await fs.rm(tmpDir, { recursive: true }) | ||
}) | ||
|
||
it('should find commmon_site_config.json', () => { | ||
site_config = frappeui() | ||
got_target = site_config.config().server.proxy[proxySource].target | ||
want_target = localhostTarget + ':' + jsonData.webserver_port | ||
assert.ok(got_target == want_target) | ||
}) | ||
|
||
it('should read the provided commmon_site_config.json', async () => { | ||
let testConfigPath = path.join(tmpDir, 'test.json') | ||
let testConfig = { webserver_port: "1002" } | ||
await fs.writeFile(testConfigPath, JSON.stringify(testConfig), 'utf8') | ||
|
||
site_config = frappeui({ site_config_path: testConfigPath }) | ||
got_target = site_config.config().server.proxy[proxySource].target | ||
want_target = localhostTarget + ':' + testConfig.webserver_port | ||
assert.ok(got_target == want_target) | ||
}) | ||
}) | ||
|
||
function ts() { | ||
const now = new Date(); | ||
const ts = now.toISOString().replace(/[-:]/g, '') | ||
return ts | ||
} |